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
- #alternative ⇒ Object
- #card ⇒ Object
- #card_id ⇒ Object
-
#codename ⇒ Symbol
Codename of card with name.
- #codename_or_string ⇒ Object
-
#standard ⇒ Card::Name
Standardized based on card names.
- #vary(variants) ⇒ Object
Instance Method Details
#alternative ⇒ Object
44 45 46 |
# File 'lib/card/name/name_variants.rb', line 44 def alternative Card.generate_alternative_name self end |
#card ⇒ Object
27 28 29 |
# File 'lib/card/name/name_variants.rb', line 27 def card Card.fetch self, new: {} end |
#card_id ⇒ Object
31 32 33 |
# File 'lib/card/name/name_variants.rb', line 31 def card_id Lexicon.id self end |
#codename ⇒ Symbol
Returns codename of card with name.
36 37 38 |
# File 'lib/card/name/name_variants.rb', line 36 def codename Codename[card_id] end |
#codename_or_string ⇒ Object
40 41 42 |
# File 'lib/card/name/name_variants.rb', line 40 def codename_or_string codename || s end |
#standard ⇒ Card::Name
Returns standardized based on card names.
17 18 19 20 21 22 23 24 25 |
# File 'lib/card/name/name_variants.rb', line 17 def standard if simple? id = Lexicon.id self std = Lexicon.name id std.present? ? std : self else self.class.compose(parts.map { |part| part.cardname.standard }) end 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 |