Class: StoreSchema::Converter::Float

Inherits:
Base
  • Object
show all
Defined in:
lib/store_schema/converter/float.rb

Constant Summary collapse

INT_FLOAT_FORMAT =

Returns an (int | float) value format.

Returns:

  • (Regexp)

    an (int | float) value format.

/^\d+|\d+\.\d+$/

Instance Attribute Summary

Attributes inherited from Base

#value

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from StoreSchema::Converter::Base

Instance Method Details

#from_dbFloat

Converts the Base#value to a Ruby-type value.

Returns:


34
35
36
# File 'lib/store_schema/converter/float.rb', line 34

def from_db
  value.to_f
end

#to_dbString, false

Converts the Base#value to a database-storable value.

Returns:


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