Class: GatherContent::Config::Element::ChoiceRadio

Inherits:
Base
  • Object
show all
Defined in:
lib/gather_content/config/elements/choice_radio.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#label, #microcopy, #name, #required

Instance Method Summary collapse

Constructor Details

#initialize(name = "", required = false, label = "", microcopy = "", other_option = false) ⇒ ChoiceRadio

Returns a new instance of ChoiceRadio.



11
12
13
14
15
# File 'lib/gather_content/config/elements/choice_radio.rb', line 11

def initialize(name = "", required = false, label = "", microcopy = "", other_option = false)
  super(name, required, label, microcopy)
  @other_option = other_option
  @options = []
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/gather_content/config/elements/choice_radio.rb', line 9

def options
  @options
end

#other_optionObject

Returns the value of attribute other_option.



9
10
11
# File 'lib/gather_content/config/elements/choice_radio.rb', line 9

def other_option
  @other_option
end

Instance Method Details

#serialize(_options = nil) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gather_content/config/elements/choice_radio.rb', line 17

def serialize(_options = nil)
  raise ArgumentError, "You need to supply at least one option" if options.size == 0

  if other_option
    verify_other_option_types!(options)
  else
    verify_option_types!(options)
  end

  verify_options!(options)

  super.merge({
    type: 'choice_radio',
    other_option: !!other_option,
    options: options.map{ |el| el.serialize(_options) }
  })
end

#to_json(options = nil) ⇒ Object



35
36
37
# File 'lib/gather_content/config/elements/choice_radio.rb', line 35

def to_json(options = nil)
  serialize.to_json(options)
end