Class: Mappable::Map
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mappable::Map
- Defined in:
- app/models/mappable/map.rb
Instance Method Summary collapse
Instance Method Details
#cached_mappings ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/mappable/map.rb', line 9 def cached_mappings @cache ||= begin self.mappings.inject({}) do |cache, m| cache[:to] ||= {} cache[:to][m.to.downcase] = m.from cache[:from] ||= {} cache[:from][m.from.downcase] = m.to cache end end end |
#value_for(mapping_name, in_value) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/models/mappable/map.rb', line 23 def value_for(mapping_name, in_value) direction = :from if to.to_sym == mapping_name direction = :to if from.to_sym == mapping_name if direction mapping = cached_mappings[direction] key = in_value.downcase mapping.nil? ? nil : mapping[key] end end |