Class: AttrTypecastable::Types::Integer

Inherits:
Base
  • Object
show all
Defined in:
lib/attr_typecastable/types/integer.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #typecast

Constructor Details

This class inherits a constructor from AttrTypecastable::Types::Base

Instance Method Details

#do_typecast(value) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/attr_typecastable/types/integer.rb', line 7

def do_typecast(value)
  return value if value.is_a?(::Integer)

  if value.respond_to?(:to_i)
    value.to_i
  else
    raise CastError, "value does not have `to_i` method"
  end
end