ismasan (owner)

Revisions

gist: 130127 Download_button fork
public
Public Clone URL: git://gist.github.com/130127.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class ManyLevels
  extend HashMapper
  map from('/name'), to('/tag_attributes/name')
  map from('/properties/type'), to('/tag_attributes/type')
  map from('/tagid'), to('/tag_id')
  map from('/properties/egg'), to('/chicken')
end
 
input = {
  :name => 'ismael',
  :tagid => 1,
  :properties => {
    :type => 'BLAH',
    :egg => 33
  }
}
 
ManyLevels.normalize(input)
 
# outputs:
     {
  :tag_id => 1,
  :chicken => 33,
  :tag_attributes => {
    :name => 'ismael',
    :type => 'BLAH'
  }
}