Class: Crowdskout::Components::Profile
- Defined in:
- lib/crowdskout/components/profiles/profile.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.create(props) ⇒ Profile
Factory method to create an Profile object from a json string.
Instance Method Summary collapse
-
#add_genders(gender) ⇒ Array
Add a Gender.
-
#add_names(name) ⇒ Array
Add a Name.
-
#to_hash ⇒ Object
Hash override to generate the correct hash.
Methods inherited from Component
get_value, to_hash_value, #to_json
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
10 11 12 |
# File 'lib/crowdskout/components/profiles/profile.rb', line 10 def collections @collections end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/crowdskout/components/profiles/profile.rb', line 10 def id @id end |
Class Method Details
.create(props) ⇒ Profile
Factory method to create an Profile object from a json string
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/crowdskout/components/profiles/profile.rb', line 15 def self.create(props) obj = Profile.new obj.collections = [] if props props.each do |key, value| if ['id'].include? key.downcase obj.send("#{key}=", value) if obj.respond_to? key else # the key is the name of the collection # the value is an array of items obj.collections << Components::Collection.create({key => value}) end end end obj end |
Instance Method Details
#add_genders(gender) ⇒ Array
Add a Gender
43 44 45 46 |
# File 'lib/crowdskout/components/profiles/profile.rb', line 43 def add_genders(gender) @genders = [] if @genders.nil? @genders << gender end |
#add_names(name) ⇒ Array
Add a Name
35 36 37 38 |
# File 'lib/crowdskout/components/profiles/profile.rb', line 35 def add_names(name) @names = [] if @names.nil? @names << name end |
#to_hash ⇒ Object
Hash override to generate the correct hash
49 50 51 52 53 54 55 |
# File 'lib/crowdskout/components/profiles/profile.rb', line 49 def to_hash ret_val = { id: id } collections.each do |collection| ret_val.merge! collection.to_hash end ret_val end |