Class: Acfs::Resource::Attributes::Boolean
- Defined in:
- lib/acfs/resource/attributes/boolean.rb
Overview
Boolean attribute type. Use it in your model as an attribute type:
Given objects will be converted to string. The following strings are considered true, everything else false:
true, on, yes
Constant Summary collapse
- FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'no', 'NO'].to_set
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#cast_value(value) ⇒ TrueClass, FalseClass
Cast given object to boolean.
Methods inherited from Base
#cast, #default_value, #initialize
Constructor Details
This class inherits a constructor from Acfs::Resource::Attributes::Base
Instance Method Details
#cast_value(value) ⇒ TrueClass, FalseClass
Cast given object to boolean.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acfs/resource/attributes/boolean.rb', line 28 def cast_value(value) return true if value == true return false if value == false if value.blank? nil else !FALSE_VALUES.include?(value) end end |