diff --git a/app/models/printing.rb b/app/models/printing.rb index 5cd6c1b..e87a5f6 100644 --- a/app/models/printing.rb +++ b/app/models/printing.rb @@ -37,10 +37,6 @@ class Printing < ApplicationRecord foreign_key: :card_id has_many :card_pools, through: :card_pool_cards - def images - { 'nrdb_classic' => nrdb_classic_images } - end - def latest_printing_id printing_ids[0] rescue StandardError @@ -59,16 +55,6 @@ def restrictions private - def nrdb_classic_images - url_prefix = Rails.configuration.x.printing_images.nrdb_classic_prefix - { - 'tiny' => format('%s/tiny/%s.jpg', url_prefix:, printing_id: id), - 'small' => format('%s/small/%s.jpg', url_prefix:, printing_id: id), - 'medium' => format('%s/medium/%s.jpg', url_prefix:, printing_id: id), - 'large' => format('%s/large/%s.jpg', url_prefix:, printing_id: id) - } - end - def packed_restriction_to_map(packed) m = {} packed.each do |p| diff --git a/app/resources/printing_resource.rb b/app/resources/printing_resource.rb index f5d9d9d..dede357 100644 --- a/app/resources/printing_resource.rb +++ b/app/resources/printing_resource.rb @@ -83,7 +83,9 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng attribute :pronunciation_approximation, :string attribute :pronunciation_ipa, :string - attribute :images, :hash + attribute :images, :hash do + images(@object.id) + end attribute :card_abilities, :hash attribute :latest_printing_id, :string attribute :restrictions, :hash @@ -96,7 +98,7 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng unless @object.num_extra_faces.zero? @object.face_indices.each do |index| - f = { index: } + f = { index:, images: images(@object.id, index) } f[:base_link] = @object.faces_base_link[index] if @object.faces_base_link[index] f[:copy_quantity] = @object.faces_copy_quantity[index] if @object.faces_copy_quantity[index] f[:flavor] = @object.faces_flavor[index] if @object.faces_flavor[index] @@ -173,4 +175,19 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng format('%s?filter[printing_id]=%s', url: Rails.application.routes.url_helpers.card_pools_url, id: p.id) end end + + private + + def images(id, face_index = nil) + url_prefix = Rails.configuration.x.printing_images.nrdb_classic_prefix + face_suffix = "-#{face_index}" unless face_index.nil? + { + 'nrdb_classic' => { + 'tiny' => "#{url_prefix}/tiny/#{id}#{face_suffix}.jpg", + 'small' => "#{url_prefix}/small/#{id}#{face_suffix}.jpg", + 'medium' => "#{url_prefix}/medium/#{id}#{face_suffix}.jpg", + 'large' => "#{url_prefix}/large/#{id}#{face_suffix}.jpg" + } + } + end end diff --git a/spec/resources/printing/reads_spec.rb b/spec/resources/printing/reads_spec.rb index 0ae5a5d..a01aca7 100644 --- a/spec/resources/printing/reads_spec.rb +++ b/spec/resources/printing/reads_spec.rb @@ -65,7 +65,7 @@ expect(data.pronouns).to eq(printing.pronouns) expect(data.pronunciation_approximation).to eq(printing.pronunciation_approximation) expect(data.pronunciation_ipa).to eq(printing.pronunciation_ipa) - expect(data.images).to eq(printing.images) + expect(data.images).not_to be(nil) expect(data.card_abilities).to eq(printing.card_abilities.stringify_keys) expect(data.latest_printing_id).to eq(printing.latest_printing_id) expect(data.restrictions).to eq(printing.restrictions.stringify_keys)