Class: Dech::HashKeyMapper
- Inherits:
-
Object
- Object
- Dech::HashKeyMapper
- Defined in:
- lib/dech/hash_key_mapper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = {}, mapping = {}) ⇒ HashKeyMapper
constructor
A new instance of HashKeyMapper.
- #map ⇒ Object
Constructor Details
#initialize(hash = {}, mapping = {}) ⇒ HashKeyMapper
Returns a new instance of HashKeyMapper.
11 12 13 14 |
# File 'lib/dech/hash_key_mapper.rb', line 11 def initialize(hash={}, mapping={}) @hash = hash @mapping = mapping end |
Class Method Details
.map(hash, mapping) ⇒ Object
6 7 8 |
# File 'lib/dech/hash_key_mapper.rb', line 6 def map(hash, mapping) new(hash, mapping).map end |
Instance Method Details
#map ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/dech/hash_key_mapper.rb', line 16 def map new_hash = {} @hash.each do |k, v| [@mapping[k] || k].flatten.each do |new_key| new_hash[new_key] = v end end new_hash end |