Class: HashMap::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_map/mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original, hash_map) ⇒ Mapper

Returns a new instance of Mapper.



4
5
6
7
# File 'lib/hash_map/mapper.rb', line 4

def initialize(original, hash_map)
  @original = Fusu::HashWithIndifferentAccess.new(original)
  @hash_map = hash_map
end

Instance Attribute Details

#hash_mapObject (readonly)

Returns the value of attribute hash_map.



3
4
5
# File 'lib/hash_map/mapper.rb', line 3

def hash_map
  @hash_map
end

#originalObject (readonly)

Returns the value of attribute original.



3
4
5
# File 'lib/hash_map/mapper.rb', line 3

def original
  @original
end

Instance Method Details

#outputObject



9
10
11
12
13
14
15
16
# File 'lib/hash_map/mapper.rb', line 9

def output
  new_hash = Fusu::HashWithIndifferentAccess.new
  hash_map.class.attributes.each do |struc|
    value = get_value(struc)
    Fusu::Hash.deep_merge!(new_hash, build_keys(struc[:key], value))
  end
  new_hash
end