Class: Crowdskout::Components::Value

Inherits:
Component
  • Object
show all
Defined in:
lib/crowdskout/components/profiles/value.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Component

get_value, #to_hash, to_hash_value, #to_json

Instance Attribute Details

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/crowdskout/components/profiles/value.rb', line 10

def id
  @id
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/crowdskout/components/profiles/value.rb', line 10

def value
  @value
end

Class Method Details

.create(props) ⇒ Value

Factory method to create an Value object from a json string

Parameters:

  • props (Hash)
    • properties to create object from

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/crowdskout/components/profiles/value.rb', line 15

def self.create(props)
  obj = Value.new
  if props
    props.each do |key, value|
      if obj.respond_to? key
        obj.send("#{key}=", value) 
      else
        # this will create the attribute if it doesn't exist
        obj.class.send(:attr_accessor, key)
        obj.instance_variable_set("@#{key}", value)
      end
    end
  end
  obj
end