Last active
August 29, 2015 14:11
-
-
Save sebastiangeiger/5dc2018b64be97827c49 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 'json' | |
require 'lazy_doc' | |
json = '{"first_name": "George", "last_name": "Washington", "worker_number": "0000001", "email": "[email protected]", "user_name": "georgie", "profile_roles" : [ { "project_name": "Work!", "role" : "PROJECT_ADMINISTRATOR" } ]}' | |
class User | |
include LazyDoc::DSL | |
def initialize(json) | |
lazily_embed(json) | |
end | |
access :first_name | |
access :last_name | |
access :profile_roles, finally: lambda {|profile_roles| profile_roles.map{|profile_role| ProfileRole.new(profile_role)}} | |
end | |
class ProfileRole | |
include LazyDoc::DSL | |
def initialize(json) | |
lazily_embed(json) | |
end | |
access :project_name | |
access :role | |
end | |
u = User.new(json) | |
p u.first_name | |
p u.last_name | |
p u.profile_roles | |
p u.profile_roles.first.project_name | |
p u.profile_roles.first.role |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment