Module: RSchema::Coercers::Boolean
Constant Summary collapse
- TRUTHY_STRINGS =
['on', '1', 'true', 'yes']
- FALSEY_STRINGS =
['off', '0', 'false', 'no']
Instance Method Summary collapse
Instance Method Details
#build(schema) ⇒ Object
10 11 12 |
# File 'lib/rschema/coercers/boolean.rb', line 10 def build(schema) self end |
#call(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rschema/coercers/boolean.rb', line 14 def call(value) case value when true, false then Result.success(value) when nil then Result.success(false) when String case when TRUTHY_STRINGS.include?(value.downcase) then Result.success(true) when FALSEY_STRINGS.include?(value.downcase) then Result.success(false) else Result.failure end else Result.failure end end |
#will_affect?(value) ⇒ Boolean
28 29 30 |
# File 'lib/rschema/coercers/boolean.rb', line 28 def will_affect?(value) true != value && false != value end |