1
0
Fork 0
forked from OpenNeo/impress

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:
Emi Matchu 2024-05-29 18:36:30 -07:00
parent 72c739ca0f
commit c78d51ab01

View file

@ -1,3 +1,5 @@
require "addressable/template"
class AltStyle < ApplicationRecord
belongs_to :species
belongs_to :color
@ -35,11 +37,20 @@ class AltStyle < ApplicationRecord
"#{series_name} #{color.human_name}"
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
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
# is named reliably!
"https://images.neopets.com/items/nostalgic_" +
"#{color.name.gsub(/\s+/, '').downcase}_#{species.name.downcase}.gif"
return DEFAULT_THUMBNAIL_URL unless has_real_series_name?
# HACK: We're assuming this is the format long-term! But if it changes, we
# 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
def preview_image_url