Class: Supernova::Solr::Mapper
- Inherits:
-
Object
- Object
- Supernova::Solr::Mapper
- Defined in:
- lib/supernova/solr/mapper.rb
Constant Summary collapse
- DEFAULT_MAPPINGS =
{ :id => :id }
- SUFFIXES =
{ :string => :s, :integer => :i, :float => :f, :boolean => :b, :multi_string => :ms, :time => :dt, :date => :dt, }
Instance Method Summary collapse
-
#initialize(mapping = {}) ⇒ Mapper
constructor
A new instance of Mapper.
- #map(hash) ⇒ Object
Constructor Details
#initialize(mapping = {}) ⇒ Mapper
Returns a new instance of Mapper.
14 15 16 17 18 19 |
# File 'lib/supernova/solr/mapper.rb', line 14 def initialize(mapping = {}) @mapping = DEFAULT_MAPPINGS.merge(mapping).inject({}) do |hash, (from, to)| hash[from] = SUFFIXES[to] ? :"#{from}_#{SUFFIXES[to]}" : to hash end end |
Instance Method Details
#map(hash) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/supernova/solr/mapper.rb', line 21 def map(hash) mapping.inject({}) do |solr_hash, (from, to)| solr_hash[to] = hash[from] solr_hash end end |