class Crowdskout::Components::Collection

Attributes

items[RW]
key_name[RW]

Public Class Methods

create(props) click to toggle source

Factory method to create an Collection object from a json string @param [String] key_name - name of the collection @param [Array] items - properties to create object from @return [Collection]

# 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

Public Instance Methods

to_hash() click to toggle source

Hash override to generate the correct hash

# File lib/crowdskout/components/profiles/collection.rb, line 33
def to_hash
  {
    key_name => items.collect(&:to_hash)
  }
end