2023-08-02 16:05:02 -07:00
|
|
|
class Color < ApplicationRecord
|
2023-12-05 18:04:54 -08:00
|
|
|
has_many :pet_types
|
2024-09-30 16:06:22 -07:00
|
|
|
has_many :alt_styles
|
2010-05-16 13:15:21 -07:00
|
|
|
|
2024-01-23 05:10:43 -08:00
|
|
|
scope :alphabetical, -> { order(:name) }
|
|
|
|
scope :basic, -> { where(basic: true) }
|
|
|
|
scope :standard, -> { where(standard: true) }
|
|
|
|
scope :nonstandard, -> { where(standard: false) }
|
2014-01-25 12:56:31 -08:00
|
|
|
|
|
|
|
validates :name, presence: true
|
2010-11-27 15:41:06 -08:00
|
|
|
|
2013-01-21 14:01:41 -08:00
|
|
|
def as_json(options={})
|
2023-12-05 18:04:54 -08:00
|
|
|
{id: id, name: name, human_name: human_name}
|
2010-11-27 15:41:06 -08:00
|
|
|
end
|
2014-03-27 20:44:18 -07:00
|
|
|
|
2013-01-21 14:01:41 -08:00
|
|
|
def human_name
|
2024-09-27 19:38:53 -07:00
|
|
|
if name
|
|
|
|
name.split(' ').map { |word| word.capitalize }.join(' ')
|
2014-03-27 20:44:18 -07:00
|
|
|
else
|
2024-09-27 19:38:53 -07:00
|
|
|
I18n.translate('colors.default_human_name')
|
2014-03-27 20:44:18 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Handle newly-released species in Item Getting Guide
This is less likely than the newly-released color case for PB items,
but I figure let's be resilient anyway, especially since it's so easy
to—and also I figure this is less likely to be triggered by an *actual*
new species, and more likely to be triggered by a surprise in an item's
naming conventions.
But yeah, if `Item#pb_species` returns `nil` upstream, it'll be passed
to `Color#example_pet_type`, which will crash trying to read its ID. So
in this change, we update `Color#example_pet_type` to accept a `nil`
value, and fall back to the first Species (Acara) in that case.
This means that, if you e.g. take the Mutant Aisha Collar and delete
the word "Aisha" from the name, then load it in the Item Getting Guide,
you'll see a thumbnail of a Mutant Acara. Good enough!
2024-06-05 19:27:38 -07:00
|
|
|
def example_pet_type(preferred_species: nil)
|
|
|
|
preferred_species ||= Species.first
|
2024-05-22 17:53:52 -07:00
|
|
|
pet_types.order([Arel.sql("species_id = ? DESC"), preferred_species.id],
|
|
|
|
"species_id ASC").first
|
|
|
|
end
|
|
|
|
|
2024-09-07 16:12:05 -07:00
|
|
|
def default_gender_presentation
|
|
|
|
if name.downcase.ends_with? "boy"
|
|
|
|
:masc
|
|
|
|
elsif name.downcase.ends_with? "girl"
|
|
|
|
:fem
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2010-05-16 12:44:32 -07:00
|
|
|
end
|