Module: Card::Name::NameVariants

Included in:
Card::Name
Defined in:
lib/card/name/name_variants.rb

Constant Summary collapse

@@variant_methods =
[: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

#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(self.s) do |name, variant|
    variant = @@variant_aliases[variant.to_sym] || variant.to_sym
    @@variant_methods.include?(variant) ? name.send(variant) : name
  end
end