Method: FlatKit::FieldType::BooleanType.coerce

Defined in:
lib/flat_kit/field_type/boolean_type.rb

.coerce(data) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/flat_kit/field_type/boolean_type.rb', line 32

def self.coerce(data)
  case data
  when TrueClass
    true
  when FalseClass
    false
  when Numeric
    return false if data.zero?
    return true  if data == 1

    CoerceFailure
  when String
    return true  if TRUTHY_REGEX.match?(data)
    return false if FALSEY_REGEX.match?(data)

    CoerceFailure
  end
end