Class: Lev::TermMapper::ScopedAndMapped
- Inherits:
-
Lev::TermMapper
- Object
- Lev::TermMapper
- Lev::TermMapper::ScopedAndMapped
- Defined in:
- lib/lev/term_mapper.rb
Instance Method Summary collapse
-
#initialize(scope = nil, mapping = nil) ⇒ ScopedAndMapped
constructor
A new instance of ScopedAndMapped.
- #map(inputs) ⇒ Object
Methods inherited from Lev::TermMapper
scope, scope_and_map, verbatim
Constructor Details
#initialize(scope = nil, mapping = nil) ⇒ ScopedAndMapped
Returns a new instance of ScopedAndMapped.
24 25 26 27 |
# File 'lib/lev/term_mapper.rb', line 24 def initialize(scope=nil, mapping=nil) @scope = scope @mapping = mapping end |
Instance Method Details
#map(inputs) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/lev/term_mapper.rb', line 29 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 |