Class: GatherContent::Config::Element::ChoiceCheckbox
- Defined in:
- lib/gather_content/config/elements/choice_checkbox.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Base
#label, #microcopy, #name, #required
Instance Method Summary collapse
-
#initialize(name = "", required = false, label = "", microcopy = "") ⇒ ChoiceCheckbox
constructor
A new instance of ChoiceCheckbox.
- #serialize(_options = nil) ⇒ Object
- #to_json ⇒ Object
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
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 8 def @options end |
Instance Method Details
#serialize(_options = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 15 def serialize( = nil) cleaned = .select{ |opt| opt.instance_of?(GatherContent::Config::Element::Option) } raise ArgumentError, "You need to supply at least one option" if .size == 0 raise ArgumentError, "Options can only be GatherContent::Config::Element::Option" if cleaned.size == 0 super.merge({ type: 'choice_checkbox', options: .map{ |el| el.serialize() } }) end |
#to_json ⇒ Object
26 27 28 |
# File 'lib/gather_content/config/elements/choice_checkbox.rb', line 26 def to_json serialize.to_json end |