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 =
/^(false|f|no|n|0)$/i- TRUTHY =
/^(true|t|yes|y|1)$/i
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ Boolean
Converts a value to a Boolean.
Instance Method Details
#call(value, options = {}) ⇒ Boolean
Converts a value to a Boolean
42 43 44 45 46 47 48 49 50 |
# File 'lib/cmdx/coercions/boolean.rb', line 42 def call(value, = {}) case value.to_s.downcase when FALSEY then false when TRUTHY then true else type = Locale.t("cmdx.types.boolean") raise CoercionError, Locale.t("cmdx.coercions.into_a", type:) end end |