Class: Crowdskout::Components::FieldOptions

Inherits:
Component
  • Object
show all
Defined in:
lib/crowdskout/components/fields/field_options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

get_value, #to_hash, to_hash_value, #to_json

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



10
11
12
# File 'lib/crowdskout/components/fields/field_options.rb', line 10

def collection
  @collection
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/crowdskout/components/fields/field_options.rb', line 10

def id
  @id
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/crowdskout/components/fields/field_options.rb', line 10

def options
  @options
end

Class Method Details

.create(props) ⇒ FieldOptions

Factory method to create an FieldOptions 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
30
31
32
# File 'lib/crowdskout/components/fields/field_options.rb', line 15

def self.create(props)
  obj = FieldOptions.new
  if props
    props.each do |key, value|
      if key.downcase == 'options'
        if value
          obj.options = []
          value.each do |option|
            obj.options << Components::Option.create(option)
          end
        end
      else
        obj.send("#{key}=", value) if obj.respond_to? key
      end
    end
  end
  obj
end

Instance Method Details

#add_options(option) ⇒ Array

Add an Option

Parameters:

Returns:

  • (Array)

    the options array



37
38
39
40
# File 'lib/crowdskout/components/fields/field_options.rb', line 37

def add_options(option)
  @options = [] if @options.nil?
  @options << option
end