Sha256: 0fb03ee3922e735bd5737785ed3f555a074138c470aa01a6efa620ca54f4fa9a

Contents?: true

Size: 793 Bytes

Versions: 38

Compression:

Stored size: 793 Bytes

Contents

module Lev

  class TermMapper

    def self.verbatim
      ScopedAndMapped.new(nil, nil)
    end

    def self.scope_and_map(scope, mapping)
      ScopedAndMapped.new(scope, mapping)
    end

    def self.scope(scope)
      ScopedAndMapped.new(scope, nil)
    end

    def map(inputs)
      raise AbstractMethodCalled
    end

  protected

    class ScopedAndMapped < TermMapper
      def initialize(scope=nil, mapping=nil)
        @scope = scope
        @mapping = mapping
      end

      def map(inputs)
        inputs = [inputs].flatten.compact
        result = inputs.collect do |input|
          mapped = (@mapping || {})[input] || input
          @scope.nil? ? mapped : [@scope, mapped].flatten
        end
        result.size == 1 ? result.first : result
      end
    end

  end

end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
lev-4.3.2 lib/lev/term_mapper.rb
lev-4.3.1 lib/lev/term_mapper.rb
lev-4.3.0 lib/lev/term_mapper.rb
lev-4.2.0 lib/lev/term_mapper.rb
lev-4.1.0 lib/lev/term_mapper.rb
lev-4.0.0 lib/lev/term_mapper.rb
lev-3.0.0 lib/lev/term_mapper.rb
lev-2.2.1 lib/lev/term_mapper.rb
lev-2.2.0 lib/lev/term_mapper.rb
lev-2.1.1 lib/lev/term_mapper.rb
lev-2.1.0 lib/lev/term_mapper.rb
lev-2.0.5 lib/lev/term_mapper.rb
lev-2.0.4 lib/lev/term_mapper.rb
lev-2.0.3 lib/lev/term_mapper.rb
lev-2.0.2 lib/lev/term_mapper.rb
lev-2.0.1 lib/lev/term_mapper.rb
lev-1.0.1 lib/lev/term_mapper.rb
lev-1.0.0 lib/lev/term_mapper.rb