Class: Crowdskout::Components::Field
- Defined in:
- lib/crowdskout/components/profiles/field.rb
Instance Attribute Summary collapse
-
#key_name ⇒ Object
value can either be a string or a hash.
-
#value ⇒ Object
value can either be a string or a hash.
Class Method Summary collapse
-
.create(props) ⇒ Field
Factory method to create an Field 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
#key_name ⇒ Object
value can either be a string or a hash
11 12 13 |
# File 'lib/crowdskout/components/profiles/field.rb', line 11 def key_name @key_name end |
#value ⇒ Object
value can either be a string or a hash
11 12 13 |
# File 'lib/crowdskout/components/profiles/field.rb', line 11 def value @value end |
Class Method Details
.create(props) ⇒ Field
Factory method to create an Field object from a json string
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/crowdskout/components/profiles/field.rb', line 17 def self.create(props) obj = Field.new props.each do |key, value| obj.key_name = key if value.is_a?(Hash) obj.value = Value.create(value) else obj.value = value end end obj end |
Instance Method Details
#to_hash ⇒ Object
Hash override to generate the correct hash
31 32 33 34 35 |
# File 'lib/crowdskout/components/profiles/field.rb', line 31 def to_hash { key_name => (value.to_hash rescue value) } end |