Class: ActiveGraph::Shared::TypeConverters::BigDecimalConverter

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

Class Method Summary collapse

Methods inherited from BaseConverter

converted?, #supports_array?

Class Method Details

.convert_typeObject



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

def convert_type
  BigDecimal
end

.db_typeObject



72
73
74
# File 'lib/active_graph/shared/type_converters.rb', line 72

def db_type
  String
end

.to_db(value) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/active_graph/shared/type_converters.rb', line 76

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



87
88
89
# File 'lib/active_graph/shared/type_converters.rb', line 87

def to_ruby(value)
  value.to_d
end