Update SummonProcessor to work like the others
This commit is contained in:
parent
e5ecfbd95f
commit
ebb3218c29
3 changed files with 13 additions and 11 deletions
|
|
@ -33,7 +33,7 @@ module Processors
|
|||
end
|
||||
|
||||
@data = @data.with_indifferent_access
|
||||
characters_data = @data['deck']['npc']
|
||||
characters_data = @data.dig('deck', 'npc')
|
||||
|
||||
grid_characters = process_characters(characters_data)
|
||||
grid_characters.each do |grid_character|
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module Processors
|
|||
# Initializes a new SummonProcessor.
|
||||
#
|
||||
# @param party [Party] the Party record.
|
||||
# @param data [Array<Hash>] an array of summon data hashes.
|
||||
# @param data [Hash] the deck hash.
|
||||
# @param type [Symbol] the type of summon (:normal, :friend, or :sub).
|
||||
# @param quick_summon_id [String, nil] (optional) the quick summon identifier.
|
||||
# @param options [Hash] additional options.
|
||||
|
|
@ -37,21 +37,23 @@ module Processors
|
|||
#
|
||||
# @return [void]
|
||||
def process
|
||||
# Guard: ensure the data is in the expected format.
|
||||
unless @data.is_a?(Hash)
|
||||
Rails.logger.error "[SUMMON] Invalid data format: expected a Hash, got #{@data.class}"
|
||||
return
|
||||
end
|
||||
|
||||
return unless @data.key?('summons') &&
|
||||
@data.key?('sub_summons') &&
|
||||
@data.key?('damage_info')
|
||||
unless @data.key?('deck') && @data['deck'].key?('pc')
|
||||
Rails.logger.error '[SUMMON] Missing npc data in deck JSON'
|
||||
return
|
||||
end
|
||||
|
||||
@data = @data.with_indifferent_access if @data.is_a?(Hash)
|
||||
@data = @data.with_indifferent_access
|
||||
summons_data = @data.dig('deck', 'pc', 'summons')
|
||||
sub_summons_data = @data.dig('deck', 'pc', 'sub_summons')
|
||||
|
||||
grid_summons = process_summons(@data['summons'], sub: false)
|
||||
grid_summons = process_summons(summons_data, sub: false)
|
||||
friend_summon = process_friend_summon
|
||||
sub_summons = process_summons(@data['sub_summons'], sub: true)
|
||||
sub_summons = process_summons(sub_summons_data, sub: true)
|
||||
|
||||
summons = [*grid_summons, friend_summon, *sub_summons]
|
||||
|
||||
|
|
@ -106,7 +108,7 @@ module Processors
|
|||
#
|
||||
# @return [GridSummon]
|
||||
def process_friend_summon
|
||||
summon_name = @data['damage_info']['summon_name']
|
||||
summon_name = @data.dig('deck', 'pc', 'damage_info', 'summon_name')
|
||||
summon = Summon.find_by('name_en = ? OR name_jp = ?', summon_name, summon_name)
|
||||
|
||||
GridSummon.new({
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ RSpec.describe Processors::SummonProcessor, type: :model do
|
|||
let(:party) { create(:party) }
|
||||
let(:deck_data) do
|
||||
file_path = Rails.root.join('spec', 'fixtures', 'deck_sample.json')
|
||||
JSON.parse(File.read(file_path))['deck']['pc']
|
||||
JSON.parse(File.read(file_path))
|
||||
end
|
||||
|
||||
subject { described_class.new(party, deck_data, language: 'en') }
|
||||
|
|
|
|||
Loading…
Reference in a new issue