Module: Card::Name::NameVariants
- Included in:
- Card::Name
- Defined in:
- lib/card/name/name_variants.rb
Constant Summary collapse
- @@variant_methods =
%i[capitalize singularize pluralize titleize downcase upcase swapcase reverse succ]
- @@variant_aliases =
{ capitalized: :capitalize, singular: :singularize, plural: :pluralize, title: :titleize }
Instance Method Summary collapse
- #card ⇒ Object
-
#card_id ⇒ Integer
Id of card with name.
-
#codename ⇒ Symbol
Codename of card with name.
-
#standard ⇒ Card::Name
Standardized based on card names.
- #vary(variants) ⇒ Object
Instance Method Details
#card ⇒ Object
21 22 23 |
# File 'lib/card/name/name_variants.rb', line 21 def card Card.fetch self end |
#card_id ⇒ Integer
Returns id of card with name.
26 27 28 |
# File 'lib/card/name/name_variants.rb', line 26 def card_id Card.fetch_id self end |
#codename ⇒ Symbol
Returns codename of card with name.
31 32 33 |
# File 'lib/card/name/name_variants.rb', line 31 def codename Codename[card_id] end |
#standard ⇒ Card::Name
Returns standardized based on card names.
17 18 19 |
# File 'lib/card/name/name_variants.rb', line 17 def standard self.class.compose(parts.map { |part| Card.fetch_name(part) || part }) end |
#vary(variants) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/card/name/name_variants.rb', line 9 def vary variants variants.to_s.split(/[\s,]+/).inject(s) do |name, variant| variant = @@variant_aliases[variant.to_sym] || variant.to_sym @@variant_methods.include?(variant) ? name.send(variant) : name end end |