Class: ShallowAttributes::Type::Integer Abstract
- Inherits:
-
Object
- Object
- ShallowAttributes::Type::Integer
- Defined in:
- lib/shallow_attributes/type/integer.rb
Overview
This class is abstract.
Abstract class for typecast object to Integer type.
Instance Method Summary collapse
-
#coerce(value, options = {}) ⇒ Integer
Convert value to Integer type.
Instance Method Details
#coerce(value, options = {}) ⇒ Integer
Convert value to Integer type
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/shallow_attributes/type/integer.rb', line 26 def coerce(value, = {}) case value when nil then [:allow_nil] ? 0 : nil when ::TrueClass then 1 when ::FalseClass then 0 else value.respond_to?(:to_i) ? value.to_i : raise(ShallowAttributes::Type::InvalidValueError, %(Invalid value "#{value}" for type "Integer")) end end |