Class: GatherContent::Config::Element::ChoiceCheckbox

Inherits:
Base
  • Object
show all
Defined in:
lib/gather_content/config/elements/choice_checkbox.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 = "") ⇒ ChoiceCheckbox



10
11
12
13
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 10

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 8

def options
  @options
end

Instance Method Details

#serialize(_options = nil) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 15

def serialize(_options = nil)
  cleaned = options.select{ |opt| opt.instance_of?(GatherContent::Config::Element::Option) }
  raise ArgumentError, "You need to supply at least one option" if options.size == 0
  raise ArgumentError, "Options can only be GatherContent::Config::Element::Option" if cleaned.size == 0

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

#to_jsonObject



26
27
28
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 26

def to_json
  serialize.to_json
end