Created
August 12, 2015 18:19
-
-
Save martinciu/2091571bdd6d13dcf82d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rom-mapper' | |
require 'json' | |
class ProfileMapper < ROM::Mapper | |
reject_keys true | |
attribute :id, from: "userId" | |
unwrap "profile" do | |
attribute :created_at, from: "firstDate" | |
# attribute :metric | |
# attribute :locale | |
unwrap "localization" do | |
attribute :metric, from: "metric" | |
attribute :locale, from: "locale" | |
end | |
end | |
end | |
json = JSON.parse([ | |
{ | |
userId: 1, | |
profile: { | |
firstDate: '2012-12-12', | |
localization: { | |
metric: true, | |
locale: 'en' | |
} | |
} | |
} | |
].to_json) | |
puts ProfileMapper.build.call(json) | |
# {:id=>1, "profile"=>{:metric=>true, :locale=>"en"}, :created_at=>"2012-12-12"} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment