Class: Bureaucrat::Widgets::NullBooleanSelect
- Defined in:
- lib/bureaucrat/widgets.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes inherited from Select
Attributes inherited from Widget
Instance Method Summary collapse
- #has_changed?(initial, data) ⇒ Boolean
-
#initialize(attrs = nil) ⇒ NullBooleanSelect
constructor
A new instance of NullBooleanSelect.
- #render(name, value, attrs = nil, choices = []) ⇒ Object
- #value_from_datahash(data, files, name) ⇒ Object
Methods inherited from Select
#render_option, #render_options
Methods inherited from Widget
#build_attrs, #hidden?, id_for_label, inherited, #initialize_copy, #media
Methods included from Utils
conditional_escape, escape, flatatt, format_string, make_bool, make_float, mark_safe, pretty_name, security_hash
Constructor Details
#initialize(attrs = nil) ⇒ NullBooleanSelect
Returns a new instance of NullBooleanSelect.
339 340 341 342 |
# File 'lib/bureaucrat/widgets.rb', line 339 def initialize(attrs=nil) choices = [['1', 'Unknown'], ['2', 'Yes'], ['3', 'No']] super(attrs, choices) end |
Instance Method Details
#has_changed?(initial, data) ⇒ Boolean
362 363 364 |
# File 'lib/bureaucrat/widgets.rb', line 362 def has_changed?(initial, data) make_bool(initial) != make_bool(data) end |
#render(name, value, attrs = nil, choices = []) ⇒ Object
344 345 346 347 348 349 350 351 |
# File 'lib/bureaucrat/widgets.rb', line 344 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_datahash(data, files, name) ⇒ Object
353 354 355 356 357 358 359 360 |
# File 'lib/bureaucrat/widgets.rb', line 353 def value_from_datahash(data, files, name) value = data[name] case value when '2', true then true when '3', false then false else nil end end |