Last active
May 20, 2016 21:42
-
-
Save colmarius/b93ed367bc9e0467621ce0209537aa14 to your computer and use it in GitHub Desktop.
Playing with ephemeral gem
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
# | |
# Playing with ephemeral gem | |
# | |
# - https://github.com/CoralineAda/ephemeral/ | |
class Base | |
include Ephemeral::Base | |
def initialize(args={}); args.each{|k,v| self.send("#{k}=", v)}; end | |
end | |
class BirthDate < Base | |
attr_accessor :day, :month, :year | |
end | |
class Address < Base | |
attr_accessor :city, :country, :email, :fax, :mobile_phone, | |
:phone, :province, :street, :zip_code | |
end | |
class School < Base | |
attr_accessor :begin_date, :degree, :end_date, :name, :notes, :subject | |
scope :economic, subject: 'economic' | |
end | |
class Qualification < Base | |
end | |
class EducationalBackground < Base | |
collects :schools | |
collects :qualifications | |
end | |
class PhotoUrls < Base | |
attr_accessor :large, :maxi_thumb, :medium_thumb, :mini_thumb, :thumb | |
end | |
class User | |
attr_accessor :active_email, :badges, :display_name, :first_name, :gender, :haves, | |
:id, :instant_messaging_accounts, :interests, :languages, :last_name, | |
:organisation_member, :page_name, :permalink, :premium_services, | |
:professional_experience, :time_zone, :wants, :web_profiles | |
has_one :birth_date | |
has_one :business_address, class_name: 'Address' | |
has_one :private_address, class_name: 'Address' | |
has_one :educational_background | |
has_one :photo_urls, class_name: 'PhotoUrls' | |
end | |
users = [ | |
{ | |
"wants"=>nil, | |
"id"=>"1234", | |
"active_email"=>"kuba@codequest.eu", | |
"permalink"=>"https://example.com/profile/Johnny", | |
"languages"=>{"en"=>nil, "de"=>nil}, | |
"page_name"=>"Johhny Bravo", | |
"first_name"=>"Johnny", | |
"instant_messaging_accounts"=>{}, | |
"last_name"=>"Bravo", | |
"photo_urls"=> | |
{"maxi_thumb"=> | |
"https://example.com/asset1234,6.70x93.jpg", | |
"thumb"=> | |
"https://example.com/asset1234,6.30x40.jpg", | |
"medium_thumb"=> | |
"https://example.com/asset1234,6.57x75.jpg", | |
"large"=> | |
"https://example.com/asset1234,6.140x185.jpg", | |
"mini_thumb"=> | |
"https://example.com/asset1234,6.18x24.jpg"}, | |
"display_name"=>"Johnny", | |
"haves"=>"ruby,rails,java,solr", | |
"professional_experience"=> | |
{"non_primary_companies"=> | |
[{"industry"=>"COMPUTER_GAMES", | |
"end_date"=>"2012-01", | |
"company_size"=>nil, | |
"tag"=>"TESTING", | |
"career_level"=>nil, | |
"begin_date"=>"2011-04", | |
"description"=>nil, | |
"name"=>"testing", | |
"url"=>nil, | |
"title"=>"Tester"}], | |
"awards"=>[], | |
"primary_company"=> | |
{"industry"=>"AIRLINES", | |
"end_date"=>nil, | |
"company_size"=>nil, | |
"tag"=>"ACME", | |
"career_level"=>nil, | |
"begin_date"=>"2012", | |
"description"=>nil, | |
"name"=>"Acme", | |
"url"=>nil, | |
"title"=>"CTO"}}, | |
"educational_background"=> | |
{"schools"=> | |
[{"end_date"=>"2010-03", | |
"notes"=>nil, | |
"begin_date"=>"2007-03", | |
"degree"=>nil, | |
"subject"=>"economic", | |
"name"=>"University of Warsaw"}], | |
"qualifications"=>[]}, | |
"business_address"=> | |
{"city"=>"Pcim", | |
"fax"=>nil, | |
"mobile_phone"=>nil, | |
"phone"=>nil, | |
"province"=>nil, | |
"email"=>nil, | |
"street"=>nil, | |
"zip_code"=>nil, | |
"country"=>"PL"}, | |
"badges"=>[], | |
"birth_date"=>{"day"=>3, "year"=>1990, "month"=>10}, | |
"organisation_member"=>nil, | |
"premium_services"=>[], | |
"private_address"=> | |
{"city"=>nil, | |
"fax"=>nil, | |
"mobile_phone"=>nil, | |
"phone"=>nil, | |
"province"=>nil, | |
"email"=>"johnny@test.eu", | |
"street"=>nil, | |
"zip_code"=>nil, | |
"country"=>nil}, | |
"time_zone"=>{"utc_offset"=>2.0, "name"=>"Europe/Warsaw"}, | |
"gender"=>"m", | |
"interests"=>"marketing, internet, photography", | |
"web_profiles"=>{} | |
}] | |
user = User.new(users.first) | |
user.business_address.city |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment