Class: Stockboy::Translations::Boolean
- Inherits:
-
Stockboy::Translator
- Object
- Stockboy::Translator
- Stockboy::Translations::Boolean
- Defined in:
- lib/stockboy/translations/boolean.rb
Overview
Convert common false-like and true-like values to proper boolean true
or false
.
Returns nil for indeterminate values. This should be chained with a default value translator like [DefaultFalse] or [DefaultTrue].
Job template DSL
Registered as :boolean
. Use with:
attributes do
active as: :boolean
end
Constant Summary collapse
- TRUTHY_VALUES =
[true, 1, '1', 't', 'T', 'true', 'TRUE', 'y', 'Y', 'yes', 'YES']
- FALSY_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'n', 'N', 'no', 'NO']
Instance Attribute Summary
Attributes inherited from Stockboy::Translator
Instance Method Summary collapse
Methods inherited from Stockboy::Translator
Constructor Details
This class inherits a constructor from Stockboy::Translator
Instance Method Details
#translate(context) ⇒ Boolean
49 50 51 52 53 54 55 |
# File 'lib/stockboy/translations/boolean.rb', line 49 def translate(context) value = field_value(context, field_key) return true if TRUTHY_VALUES.include?(value) return false if FALSY_VALUES.include?(value) return nil end |