Class: Bureaucrat::Widgets::NullBooleanSelect

Inherits:
Select
  • Object
show all
Defined in:
lib/bureaucrat/widgets.rb

Constant Summary

Constants included from Utils

Utils::ESCAPES

Instance Attribute Summary

Attributes inherited from Select

#choices

Attributes inherited from Widget

#attrs, #is_required

Instance Method Summary collapse

Methods inherited from Select

#render_option, #render_options

Methods inherited from Widget

#build_attrs, #hidden?, id_for_label, #initialize_copy, #needs_multipart?

Methods included from Utils

#blank_value?, #conditional_escape, #escape, #flatatt, #format_string, #make_bool, #make_float, #mark_safe, #pretty_name

Constructor Details

#initialize(attrs = nil) ⇒ NullBooleanSelect

Returns a new instance of NullBooleanSelect.



364
365
366
367
# File 'lib/bureaucrat/widgets.rb', line 364

def initialize(attrs=nil)
  choices = [['1', 'Unknown'], ['2', 'Yes'], ['3', 'No']]
  super(attrs, choices)
end

Instance Method Details

#has_changed?(initial, data) ⇒ Boolean

Returns:

  • (Boolean)


386
387
388
389
390
391
392
393
394
395
396
# File 'lib/bureaucrat/widgets.rb', line 386

def has_changed?(initial, data)
  unless initial.nil?
    initial = make_bool(initial)
  end

  unless data.nil?
    data = make_bool(data)
  end

  initial != data
end

#render(name, value, attrs = nil, choices = []) ⇒ Object



369
370
371
372
373
374
375
376
# File 'lib/bureaucrat/widgets.rb', line 369

def render(name, value, attrs=nil, choices=[])
  value = case value
          when true, '2' then '2'
          when false, '3' then '3'
          else '1'
          end
  super(name, value, attrs, choices)
end

#value_from_formdata(data, name) ⇒ Object



378
379
380
381
382
383
384
# File 'lib/bureaucrat/widgets.rb', line 378

def value_from_formdata(data, name)
  case data[name]
  when '2', true, 'true' then true
  when '3', false, 'false' then false
  else nil
  end
end