Sha256: 6453505d5da083b70c4a1d64338807a35bc9eaaf45e861b95b3fde58c1e19506

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

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

      # @return [Card::Name] standardized based on card names
      def standard
        self.class.compose(parts.map { |part| Card.fetch_name(part) || part })
      end

      def card
        Card.fetch self
      end

      # @return [Integer] id of card with name
      def card_id
        Card.fetch_id self
      end

      # @return [Symbol] codename of card with name
      def codename
        Codename[card_id]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
card-1.100.0 lib/card/name/name_variants.rb
card-1.99.6 lib/card/name/name_variants.rb
card-1.99.5 lib/card/name/name_variants.rb
card-1.99.4 lib/card/name/name_variants.rb
card-1.99.3 lib/card/name/name_variants.rb
card-1.99.2 lib/card/name/name_variants.rb