Class: Crowdskout::Components::Item
- Defined in:
- lib/crowdskout/components/profiles/item.rb
Instance Attribute Summary collapse
-
#delete ⇒ Object
Returns the value of attribute delete.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.create(props) ⇒ Item
Factory method to create an Item object from a json string.
Instance Method Summary collapse
-
#to_hash ⇒ Object
Hash override to generate the correct hash.
Methods inherited from Component
get_value, to_hash_value, #to_json
Instance Attribute Details
#delete ⇒ Object
Returns the value of attribute delete.
10 11 12 |
# File 'lib/crowdskout/components/profiles/item.rb', line 10 def delete @delete end |
#fields ⇒ Object
Returns the value of attribute fields.
10 11 12 |
# File 'lib/crowdskout/components/profiles/item.rb', line 10 def fields @fields end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/crowdskout/components/profiles/item.rb', line 10 def id @id end |
Class Method Details
.create(props) ⇒ Item
Factory method to create an Item object from a json string
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/crowdskout/components/profiles/item.rb', line 15 def self.create(props) obj = Item.new obj.id = 0 obj.fields = [] if props props.each do |key, value| if ['id'].include? key.downcase obj.send("#{key}=", value) if obj.respond_to? key else # key is the name of the field # value is the field's value obj.fields << Components::Field.create({key => value}) end end end obj end |
Instance Method Details
#to_hash ⇒ Object
Hash override to generate the correct hash
34 35 36 37 38 39 40 |
# File 'lib/crowdskout/components/profiles/item.rb', line 34 def to_hash ret_val = { id: id } fields.each do |field| ret_val.merge! field.to_hash end ret_val end |