Class: StoreSchema::Converter::Integer

Inherits:
Base
  • Object
show all
Defined in:
lib/store_schema/converter/integer.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_dbInteger

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

Returns:



28
29
30
# File 'lib/store_schema/converter/integer.rb', line 28

def from_db
  value.to_i
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
# File 'lib/store_schema/converter/integer.rb', line 9

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