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



74
75
76
# File 'lib/active_graph/shared/type_converters.rb', line 74

def convert_type
  BigDecimal
end

.db_typeObject



78
79
80
# File 'lib/active_graph/shared/type_converters.rb', line 78

def db_type
  String
end

.to_db(value) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/active_graph/shared/type_converters.rb', line 82

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



93
94
95
# File 'lib/active_graph/shared/type_converters.rb', line 93

def to_ruby(value)
  value.to_d
end