hensei-api/lib/granblue/transformers/base_transformer.rb
Justin Edmund 0d5d4d5f59
Jedmund/import (#167)
* Move app/helpers/granblue_wiki to lib/parsers/wiki

This clears up the namespace beginning with "Granblue"

* Removed some top-level Granblue libs

DataImporter and DownloadManager exist inside of the PostDeployment namespace now so these files are redundant

* Fix Downloaders namespace

Our namespace was singular Downloader, now it is plural Downloaders to match the folder name

* Fix import paths

* DownloadManager was moved to downloaders/
* import_data task now uses the PostDeployment version of DataImporter

* Update application.rb

Eager-Load/Autoload the lib/ folder

* Update cors.rb

Add Granblue website and Extension ID to CORS

* Add transformers

Transformers take raw data from Granblue Fantasy and transforms them into hensei-compatible JSON. Transformers heavily borrow from vazkii/hensei-transfer.

* Add ImportController and route

This adds the controller that handles creating a full party from transformed Granblue Fantasy data
2025-01-17 12:02:12 -08:00

74 lines
1.8 KiB
Ruby

# frozen_string_literal: true
module Granblue
module Transformers
class TransformerError < StandardError
attr_reader :details
def initialize(message, details = nil)
@details = details
super(message)
end
end
class BaseTransformer
ELEMENT_MAPPING = {
0 => nil,
1 => 4, # Wind -> Earth
2 => 2, # Fire -> Fire
3 => 3, # Water -> Water
4 => 1, # Earth -> Wind
5 => 6, # Dark -> Light
6 => 5 # Light -> Dark
}.freeze
def initialize(data, options = {})
@data = data
@options = options
@language = options[:language] || 'en'
Rails.logger.info "[TRANSFORM] Initializing #{self.class.name} with data: #{data.class}"
validate_data
end
def transform
raise NotImplementedError, "#{self.class} must implement #transform"
end
protected
attr_reader :data, :options, :language
def validate_data
Rails.logger.info "[TRANSFORM] Validating data: #{data.inspect[0..100]}..."
if data.nil?
Rails.logger.info "[TRANSFORM] Data is nil"
return true
end
if data.empty?
Rails.logger.info "[TRANSFORM] Data is empty"
return true
end
# Data validation successful
true
end
def get_master_param(obj)
return [nil, nil] unless obj.is_a?(Hash)
master = obj['master']
param = obj['param']
Rails.logger.debug "[TRANSFORM] Extracted master: #{!!master}, param: #{!!param}"
[master, param]
end
def log_debug(message)
return unless options[:debug]
Rails.logger.debug "[TRANSFORM-DEBUG] #{self.class.name}: #{message}"
end
end
end
end