Module: CMDx::Coercions::Integer
Overview
Converts various input types to Integer format
Handles conversion from strings, numbers, and other values to integers using Ruby’s Integer() method. Raises CoercionError for values that cannot be converted to integers.
Instance Method Summary collapse
-
#call(value, options = EMPTY_HASH) ⇒ Integer
Converts a value to an Integer.
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Integer
Converts a value to an Integer
38 39 40 41 42 43 |
# File 'lib/cmdx/coercions/integer.rb', line 38 def call(value, = EMPTY_HASH) Integer(value) rescue ArgumentError, FloatDomainError, RangeError, TypeError type = Locale.t("cmdx.types.integer") raise CoercionError, Locale.t("cmdx.coercions.into_an", type:) end |