Class: Realize::Type::Boolean
Overview
Convert input into either true, false, or nil. By default nils will return false unless nullable: true is passed in. This transformer is very liberal in its parsing and will return true for:
true, 'true', 't', 'TRUE', 'True', 1, '1', 'Y', 'yes', 'Yes', 'YES'
All other non-truthy values will evaluate to false, such as:
false, 'false', 'f', 'FALSE', 'False', 0, '0', 'N', 'no', 'No', 'NO', {}, [], '',
'abc', 123, :abc, etc...
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Realize::Type::Base
Instance Method Details
#transform(_resolver, value, _time, _record) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/realize/type/boolean.rb', line 22 def transform(_resolver, value, _time, _record) if nullable && value.nil? nil else truthy?(value) end end |