Class: StoreSchema::Converter::Float
- Defined in:
- lib/store_schema/converter/float.rb
Constant Summary collapse
- INT_FLOAT_FORMAT =
Returns an (int | float) value format.
/^\d+|\d+\.\d+$/
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#from_db ⇒ Float
Converts the Base#value to a Ruby-type value.
-
#to_db ⇒ String, false
Converts the Base#value to a database-storable value.
Methods inherited from Base
Constructor Details
This class inherits a constructor from StoreSchema::Converter::Base
Instance Method Details
#from_db ⇒ Float
Converts the Base#value to a Ruby-type value.
34 35 36 |
# File 'lib/store_schema/converter/float.rb', line 34 def from_db value.to_f end |
#to_db ⇒ String, false
Converts the Base#value to a database-storable value.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/store_schema/converter/float.rb', line 13 def to_db case value when ::Integer value.to_f.to_s when ::Float value.to_s when ::String if value.match(INT_FLOAT_FORMAT) value.to_f.to_s else false end else false end end |