Class: Wizardry::Questions::Radios

Inherits:
Answer
  • Object
show all
Defined in:
lib/wizardry/questions/radios.rb

Defined Under Namespace

Classes: RadioOption

Instance Attribute Summary collapse

Attributes inherited from Answer

#name

Instance Method Summary collapse

Methods inherited from Answer

#extra_kwargs

Constructor Details

#initialize(name, options) ⇒ Radios

Returns a new instance of Radios.



8
9
10
11
12
13
14
# File 'lib/wizardry/questions/radios.rb', line 8

def initialize(name, options)
  Rails.logger.debug("🧙 Adding radios '#{name}' with options #{options}")

  @options = options

  super(name)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/wizardry/questions/radios.rb', line 4

def options
  @options
end

Instance Method Details

#build_optionsObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/wizardry/questions/radios.rb', line 24

def build_options
  case options
  when Array
    options.map { |v| Wizardry::Questions::Radios::RadioOption.new(value: v, label: v) }
  when Hash
    options.map { |k, v| Wizardry::Questions::Radios::RadioOption.new(value: k, label: v) }
  else
    fail ArgumentError, "Options must be an Hash or Array"
  end
end

#extra_argsObject



20
21
22
# File 'lib/wizardry/questions/radios.rb', line 20

def extra_args
  [build_options, :value, :label]
end

#form_methodObject



16
17
18
# File 'lib/wizardry/questions/radios.rb', line 16

def form_method
  :govuk_collection_radio_buttons
end