Class: Dynamoid::TypeCasting::NumberTypeCaster

Inherits:
Base
  • Object
show all
Defined in:
lib/dynamoid/type_casting.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Dynamoid::TypeCasting::Base

Instance Method Details

#process(value) ⇒ Object


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dynamoid/type_casting.rb', line 91

def process(value)
  if value == true
    1
  elsif value == false
    0
  elsif value.is_a?(Symbol)
    value.to_s.to_d
  elsif value.is_a?(String) && value.blank?
    nil
  elsif value.is_a?(Float) && !value.finite?
    nil
  elsif !value.respond_to?(:to_d)
    nil
  else
    value.to_d
  end
end