Class: Crowdskout::Components::Attribute

Inherits:
Component
  • Object
show all
Defined in:
lib/crowdskout/components/attributes/attribute.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

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/crowdskout/components/attributes/attribute.rb', line 10

def id
  @id
end

#lockedObject

Returns the value of attribute locked.



10
11
12
# File 'lib/crowdskout/components/attributes/attribute.rb', line 10

def locked
  @locked
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/crowdskout/components/attributes/attribute.rb', line 10

def name
  @name
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/crowdskout/components/attributes/attribute.rb', line 10

def options
  @options
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/crowdskout/components/attributes/attribute.rb', line 10

def type
  @type
end

Class Method Details

.create(props) ⇒ Attribute

Factory method to create an Attribute 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/attributes/attribute.rb', line 15

def self.create(props)
  obj = Attribute.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/attributes/attribute.rb', line 37

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