Class: ReeMapper::Float
- Inherits:
-
AbstractType
- Object
- AbstractType
- ReeMapper::Float
- Defined in:
- lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb', line 14 def cast(value) if value.is_a?(Numeric) value.to_f elsif value.is_a?(String) begin Float(value) rescue ArgumentError raise ReeMapper::CoercionError.new("is invalid float, got `#{truncate(value.inspect)}`") end elsif defined?(BigDecimal) && value.is_a?(BigDecimal) value.to_f else raise ReeMapper::TypeError.new("should be a float, got `#{truncate(value.inspect)}`") end end |
#db_dump(value) ⇒ Object
31 32 33 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb', line 31 def db_dump(value) serialize(value) end |
#db_load(value) ⇒ Object
36 37 38 |
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/float.rb', line 36 def db_load(value) cast(value) end |