class Crowdskout::Components::Item

Attributes

delete[RW]
fields[RW]
id[RW]

Public Class Methods

create(props) click to toggle source

Factory method to create an Item object from a json string @param [Hash] props - properties to create object from @return [Item]

# 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

Public Instance Methods

to_hash() click to toggle source

Hash override to generate the correct hash

# 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