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

Instance Method Details

#alternativeObject



38
39
40
# File 'lib/card/name/name_variants.rb', line 38

def alternative
  Card.generate_alternative_name self
end

#cardObject



21
22
23
# File 'lib/card/name/name_variants.rb', line 21

def card
  Card.fetch self, new: {}
end

#card_idObject



25
26
27
# File 'lib/card/name/name_variants.rb', line 25

def card_id
  Lexicon.id self
end

#codenameSymbol

Returns codename of card with name.

Returns:

  • (Symbol)

    codename of card with name



30
31
32
# File 'lib/card/name/name_variants.rb', line 30

def codename
  Codename[card_id]
end

#codename_or_stringObject



34
35
36
# File 'lib/card/name/name_variants.rb', line 34

def codename_or_string
  codename || s
end

#standardCard::Name

Returns standardized based on card names.

Returns:

  • (Card::Name)

    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