Class: ActiveAttr::Typecasting::IntegerTypecaster
- Inherits:
-
Object
- Object
- ActiveAttr::Typecasting::IntegerTypecaster
- Defined in:
- lib/active_attr/typecasting/integer_typecaster.rb
Overview
Typecasts an Object to an Integer
Instance Method Summary collapse
-
#call(value) ⇒ Integer?
Typecasts an object to an Integer.
Instance Method Details
#call(value) ⇒ Integer?
Typecasts an object to an Integer
Attempts to convert using #to_i. Handles FloatDomainError if the object is INFINITY or NAN.
25 26 27 28 |
# 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 |