Class: ShallowAttributes::Type::Boolean Abstract
- Inherits:
-
Object
- Object
- ShallowAttributes::Type::Boolean
- Defined in:
- lib/shallow_attributes/type/boolean.rb
Overview
This class is abstract.
Abstract class for typecast object to Boolean type.
Constant Summary collapse
- TRUE_VALUES =
Array of true values
[true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].freeze
- FALSE_VALUES =
Array of false values
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', nil].freeze
Instance Method Summary collapse
-
#coerce(value, options = {}) ⇒ boolean
Convert value to Boolean type.
Instance Method Details
#coerce(value, options = {}) ⇒ boolean
Convert value to Boolean type
42 43 44 45 46 47 48 49 50 |
# File 'lib/shallow_attributes/type/boolean.rb', line 42 def coerce(value, = {}) if TRUE_VALUES.include?(value) true elsif FALSE_VALUES.include?(value) false else raise ShallowAttributes::Type::InvalidValueError, %(Invalid value "#{value}" for type "Boolean") end end |