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-12.1.0 lib/lev/term_mapper.rb
lev-12.0.0 lib/lev/term_mapper.rb
lev-11.0.0 lib/lev/term_mapper.rb
lev-10.1.0 lib/lev/term_mapper.rb
lev-10.0.0 lib/lev/term_mapper.rb
lev-9.0.4 lib/lev/term_mapper.rb
lev-9.0.3 lib/lev/term_mapper.rb
lev-9.0.2 lib/lev/term_mapper.rb
lev-9.0.1 lib/lev/term_mapper.rb
lev-9.0.0 lib/lev/term_mapper.rb
lev-8.1.0 lib/lev/term_mapper.rb
lev-8.0.0 lib/lev/term_mapper.rb
lev-7.1.0 lib/lev/term_mapper.rb
lev-7.0.3 lib/lev/term_mapper.rb
lev-2.2.2 lib/lev/term_mapper.rb
lev-7.0.2 lib/lev/term_mapper.rb
lev-7.0.1 lib/lev/term_mapper.rb
lev-7.0.0 lib/lev/term_mapper.rb
lev-6.0.0 lib/lev/term_mapper.rb
lev-5.0.0 lib/lev/term_mapper.rb