Class: Neo4j::Shared::TypeConverters::BigDecimalConverter

Inherits:
BaseConverter
  • Object
show all
Defined in:
lib/neo4j/shared/type_converters.rb

Class Method Summary collapse

Methods inherited from BaseConverter

converted?, #supports_array?

Class Method Details

.convert_typeObject



64
65
66
# File 'lib/neo4j/shared/type_converters.rb', line 64

def convert_type
  BigDecimal
end

.db_typeObject



68
69
70
# File 'lib/neo4j/shared/type_converters.rb', line 68

def db_type
  String
end

.to_db(value) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/neo4j/shared/type_converters.rb', line 72

def to_db(value)
  case value
  when Rational
    value.to_f.to_d
  when respond_to?(:to_d)
    value.to_d
  else
    BigDecimal(value.to_s)
  end.to_s
end

.to_ruby(value) ⇒ Object



83
84
85
# File 'lib/neo4j/shared/type_converters.rb', line 83

def to_ruby(value)
  value.to_d
end