Module: Endeca::Transformer
- Included in:
- Document
- Defined in:
- lib/endeca/transformer.rb
Instance Method Summary collapse
-
#map(mapping = {}) ⇒ Object
Requires existence of mappings accessor (Hash).
-
#transform_query_options(query_options) ⇒ Object
Use the mappings hash to replace domain level query query_options with their Endeca equivalent.
Instance Method Details
#map(mapping = {}) ⇒ Object
Requires existence of mappings accessor (Hash)
Examples
# Standard map call that returns an Endeca::Map object
map(:old_name => :new_name)
# Allows to to create a map object to perform other functionality such
# as transformations.
map(:new_name)
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/endeca/transformer.rb', line 12 def map(mapping = {}) mapping = {mapping => mapping} if Symbol === mapping mapping = mapping.symbolize_keys if mapping.length > 1 raise ArgumentError, "map only accepts one key=>value pair" end mapping.each do |key, transformed_key| transformed_key = key unless transformed_key return mappings[key] = Map.new(key, transformed_key) end end |
#transform_query_options(query_options) ⇒ Object
Use the mappings hash to replace domain level query query_options with their Endeca equivalent.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/endeca/transformer.rb', line 28 def () query = .symbolize_keys query.keys.each do |key| if mapping = mappings[key] = mapping.perform(query) query.delete(key) query.update() end end query end |