Sha256: de23f692aea6257b3a38b6a244a0993c880bdbf841455f436050399b25705811

Contents?: true

Size: 947 Bytes

Versions: 8

Compression:

Stored size: 947 Bytes

Contents

module LanguageCards
  class Mappings
    def initialize mapping, collection=nil
      @collection = collection
      @mappings = {}
      mapping.each do |h|
        index = h.delete("index")
        begin
          a,b = h.reduce
        rescue LocalJumpError
          raise InvalidMapping
        end
        a = I18n.t "LanguageName.#{a}"
        b = I18n.t "LanguageName.#{b}"

        @mappings["#{a} => #{b}"] = {
          h => index
        }
      end
    end

    def select_mapping string
      Comparator.new string, self, @collection
    end

    def classes s=nil
      keys.map do |names|
        [s, names].compact.join(JOIN)
      end
    end

    def [] key
      @mappings[key]
    end

    def has_key? key
      @mappings.has_key? key
    end

    def keys
      @mappings.keys
    end

    class InvalidMapping < StandardError
      def initialize
        super(I18n.t 'Errors.InvalidMapping')
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
language_cards-0.1.3 lib/language_cards/mappings.rb
language_cards-0.1.2 lib/language_cards/mappings.rb
language_cards-0.1.1 lib/language_cards/mappings.rb
language_cards-0.1.0 lib/language_cards/mappings.rb
language_cards-0.0.7 lib/language_cards/mappings.rb
language_cards-0.0.6 lib/language_cards/mappings.rb
language_cards-0.0.5 lib/language_cards/mappings.rb
language_cards-0.0.4 lib/language_cards/mappings.rb