Sha256: 626207684889954ad27c4ab72f982161b43c74915481ebcd12a8dd08cdbc5287

Contents?: true

Size: 616 Bytes

Versions: 8

Compression:

Stored size: 616 Bytes

Contents

class Card
  class Name
    module NameVariants
      @@variant_methods = %i[capitalize singularize pluralize titleize
                             downcase upcase swapcase reverse succ]
      @@variant_aliases = { capitalized: :capitalize, singular: :singularize,
                            plural: :pluralize,       title: :titleize }

      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
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
card-1.99.1 lib/card/name/name_variants.rb
card-1.99.0 lib/card/name/name_variants.rb
card-1.98.3 lib/card/name/name_variants.rb
card-1.98.2 lib/card/name/name_variants.rb
card-1.98.1 lib/card/name/name_variants.rb
card-1.98.0 lib/card/name/name_variants.rb
card-1.97.0.1 lib/card/name/name_variants.rb
card-1.97.0 lib/card/name/name_variants.rb