Module: CMDx::Coercions::Boolean
Overview
Converts various input types to Boolean format
Handles conversion from strings, numbers, and other values to boolean using predefined truthy and falsey patterns.
Constant Summary collapse
- FALSEY =
/\A(false|f|no|n|0)\z/i- TRUTHY =
/\A(true|t|yes|y|1)\z/i
Instance Method Summary collapse
-
#call(value, options = EMPTY_HASH) ⇒ Boolean
Converts a value to a Boolean.
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Boolean
Converts a value to a Boolean
46 47 48 49 50 51 52 53 54 |
# File 'lib/cmdx/coercions/boolean.rb', line 46 def call(value, = EMPTY_HASH) case value.to_s when FALSEY, EMPTY_STRING then false when TRUTHY then true else type = Locale.t("cmdx.types.boolean") raise CoercionError, Locale.t("cmdx.coercions.into_a", type:) end end |