Class: CckForms::ParameterTypeClass::Boolean

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/cck_forms/parameter_type_class/boolean.rb

Overview

Represents a single checkbox.

Instance Method Summary collapse

Instance Method Details

#build_form(form_builder, options) ⇒ Object

Checkbox HTML



22
23
24
25
# File 'lib/cck_forms/parameter_type_class/boolean.rb', line 22

def build_form(form_builder, options)
  set_value_in_hash options
  form_builder.check_box :value, options.merge(value: 1, checked: value?)
end

#mongoizeObject

Anything -> boolean



12
13
14
# File 'lib/cck_forms/parameter_type_class/boolean.rb', line 12

def mongoize
  value?
end

#to_s(_options = nil) ⇒ Object

‘yes/no’ string



17
18
19
# File 'lib/cck_forms/parameter_type_class/boolean.rb', line 17

def to_s(_options = nil)
  value? ? I18n.t('cck_forms.boolean.yes') : I18n.t('cck_forms.boolean.no')
end

#value?Boolean

Is it true?

Returns:



7
8
9
# File 'lib/cck_forms/parameter_type_class/boolean.rb', line 7

def value?
  value.present? && value != '0'
end