Class: StoreSchema::Converter::Float

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

Instance Attribute Summary

Attributes included from Base

#value

Instance Method Summary collapse

Methods included from Base

#initialize

Instance Method Details

#from_dbFloat

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

Returns:



31
32
33
# File 'lib/store_schema/converter/float.rb', line 31

def from_db
  value.to_f
end

#to_dbString, false

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

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/store_schema/converter/float.rb', line 10

def to_db
  case value
  when ::Integer
    value.to_f.to_s
  when ::Float
    value.to_s
  when ::String
    if value =~ /^\d+|\d+\.\d+$/
      value.to_f.to_s
    else
      false
    end
  else
    false
  end
end