Sha256: 0c04acdccc04ee5228d13ec34707e10c56c5cda5ca4c3b8d7b5738b5c6dad08b

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

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 order key # what was my intention in design here?
      self[key].values.flatten
    end

    def keys
      @mappings.keys
    end

    def inspect
      @mappings.keys
    end

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
language_cards-0.0.1 lib/language_cards/mapping.rb