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