Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions app/models/printing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,16 +55,6 @@ def restrictions

private

def nrdb_classic_images
url_prefix = Rails.configuration.x.printing_images.nrdb_classic_prefix
{
'tiny' => format('%<url_prefix>s/tiny/%<printing_id>s.jpg', url_prefix:, printing_id: id),
'small' => format('%<url_prefix>s/small/%<printing_id>s.jpg', url_prefix:, printing_id: id),
'medium' => format('%<url_prefix>s/medium/%<printing_id>s.jpg', url_prefix:, printing_id: id),
'large' => format('%<url_prefix>s/large/%<printing_id>s.jpg', url_prefix:, printing_id: id)
}
end

def packed_restriction_to_map(packed)
m = {}
packed.each do |p|
Expand Down
21 changes: 19 additions & 2 deletions app/resources/printing_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -173,4 +175,19 @@ class PrintingResource < ApplicationResource # rubocop:disable Metrics/ClassLeng
format('%<url>s?filter[printing_id]=%<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
2 changes: 1 addition & 1 deletion spec/resources/printing/reads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading