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