Don't hardcode the series name in AltStyle thumbnail_url
This is just a bit of future-proofing! We also add a default thumbnail URL of the cute "Neopets Circle Background", for cases where the series name isn't known yet.
This commit is contained in:
parent
72c739ca0f
commit
c78d51ab01
1 changed files with 15 additions and 4 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require "addressable/template"
|
||||||
|
|
||||||
class AltStyle < ApplicationRecord
|
class AltStyle < ApplicationRecord
|
||||||
belongs_to :species
|
belongs_to :species
|
||||||
belongs_to :color
|
belongs_to :color
|
||||||
|
@ -35,11 +37,20 @@ class AltStyle < ApplicationRecord
|
||||||
"#{series_name} #{color.human_name}"
|
"#{series_name} #{color.human_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
THUMBNAIL_URL_TEMPLATE = Addressable::Template.new(
|
||||||
|
"https://images.neopets.com/items/{series}_{color}_{species}.gif"
|
||||||
|
)
|
||||||
|
DEFAULT_THUMBNAIL_URL = "https://images.neopets.com/items/mall_bg_circle.gif"
|
||||||
def thumbnail_url
|
def thumbnail_url
|
||||||
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
|
return DEFAULT_THUMBNAIL_URL unless has_real_series_name?
|
||||||
# is named reliably!
|
|
||||||
"https://images.neopets.com/items/nostalgic_" +
|
# HACK: We're assuming this is the format long-term! But if it changes, we
|
||||||
"#{color.name.gsub(/\s+/, '').downcase}_#{species.name.downcase}.gif"
|
# may need to add it as a database field instead.
|
||||||
|
THUMBNAIL_URL_TEMPLATE.expand(
|
||||||
|
series: series_name.gsub(/\s+/, '').downcase,
|
||||||
|
color: color.name.gsub(/\s+/, '').downcase,
|
||||||
|
species: species.name.gsub(/\s+/, '').downcase,
|
||||||
|
).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview_image_url
|
def preview_image_url
|
||||||
|
|
Loading…
Reference in a new issue