Class: Crowdskout::Components::Collection
- Defined in:
- lib/crowdskout/components/profiles/collection.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#key_name ⇒ Object
Returns the value of attribute key_name.
Class Method Summary collapse
-
.create(props) ⇒ Collection
Factory method to create an Collection 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
#items ⇒ Object
Returns the value of attribute items.
10 11 12 |
# File 'lib/crowdskout/components/profiles/collection.rb', line 10 def items @items end |
#key_name ⇒ Object
Returns the value of attribute key_name.
10 11 12 |
# File 'lib/crowdskout/components/profiles/collection.rb', line 10 def key_name @key_name end |
Class Method Details
.create(props) ⇒ Collection
Factory method to create an Collection object from a json string
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/crowdskout/components/profiles/collection.rb', line 16 def self.create(props) obj = Collection.new obj.items = [] props.each do |key, value| obj.key_name = key if value.is_a?(Hash) || value.is_a?(Array) value.each do |collection| obj.items << Components::Item.create(collection) end else obj.items << Components::Item.create({ key => value }) end end obj end |
Instance Method Details
#to_hash ⇒ Object
Hash override to generate the correct hash
33 34 35 36 37 |
# File 'lib/crowdskout/components/profiles/collection.rb', line 33 def to_hash { key_name => items.collect(&:to_hash) } end |