Class: StoreSchema::Converter::Float

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

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:



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

def from_db
  value.to_f
end

#to_dbString, false

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

Returns:



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

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