Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created June 15, 2009 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/130127 to your computer and use it in GitHub Desktop.
Save ismasan/130127 to your computer and use it in GitHub Desktop.
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'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment