Module: CMDx::Coercions::Integer

Extended by:
Integer
Included in:
Integer
Defined in:
lib/cmdx/coercions/integer.rb

Overview

Coerces to Integer via ‘Kernel#Integer` (strict; rejects floats-as-strings).

Instance Method Summary collapse

Instance Method Details

#call(value, options = EMPTY_HASH) ⇒ Integer, Coercions::Failure

Parameters:

  • value (Object)
  • options (Hash{Symbol => Object}) (defaults to: EMPTY_HASH)

Options Hash (options):

  • reserved (Object)

    for future per-coercion configuration (currently ignored)

Returns:



14
15
16
17
18
19
# File 'lib/cmdx/coercions/integer.rb', line 14

def call(value, options = EMPTY_HASH)
  Integer(value)
rescue ArgumentError, FloatDomainError, RangeError, TypeError
  type = I18nProxy.t("cmdx.types.integer")
  Failure.new(I18nProxy.t("cmdx.coercions.into_an", type:))
end