class Dech::HashKeyMapper

Public Class Methods

map(hash, mapping) click to toggle source
# File lib/dech/hash_key_mapper.rb, line 6
def map(hash, mapping)
  new(hash, mapping).map
end
new(hash={}, mapping={}) click to toggle source
# File lib/dech/hash_key_mapper.rb, line 11
def initialize(hash={}, mapping={})
  @hash = hash
  @mapping = mapping
end

Public Instance Methods

map() click to toggle source
# 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