Class: ActiveAttr::Typecasting::IntegerTypecaster

Inherits:
Object
  • Object
show all
Defined in:
lib/active_attr/typecasting/integer_typecaster.rb

Overview

Typecasts an Object to an Integer

Examples:

Usage

IntegerTypecaster.new.call("1") #=> 1

Since:

  • 0.5.0

Instance Method Summary collapse

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.

Examples:

Typecast a String

typecaster.call("1") #=> 1

Since:

  • 0.5.0



23
24
25
26
# File 'lib/active_attr/typecasting/integer_typecaster.rb', line 23

def call(value)
  value.to_i if value.respond_to? :to_i
rescue FloatDomainError
end