class Realize::Type::Boolean

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...

Public Instance Methods

transform(_resolver, value, _time, _record) click to toggle source
# File lib/realize/type/boolean.rb, line 22
def transform(_resolver, value, _time, _record)
  if nullable && value.nil?
    nil
  else
    truthy?(value)
  end
end

Private Instance Methods

truthy?(value) click to toggle source
# File lib/realize/type/boolean.rb, line 32
def truthy?(value)
  value.to_s.match?(/(true|t|yes|y|1)$/i)
end