class ActiveAttr::Typecasting::IntegerTypecaster
Typecasts an Object
to an Integer
@example Usage
IntegerTypecaster.new.call("1") #=> 1
@since 0.5.0
Public Instance Methods
call(value)
click to toggle source
Typecasts an object to an Integer
Attempts to convert using to_i. Handles FloatDomainError if the object is INFINITY or NAN.
@example Typecast a String
typecaster.call("1") #=> 1
@param [Object, to_i] value The object to typecast
@return [Integer, nil] The result of typecasting
@since 0.5.0
# File lib/active_attr/typecasting/integer_typecaster.rb, line 25 def call(value) value.to_i if value.present? && value.respond_to?(:to_i) rescue FloatDomainError end