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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dynamoid/type_casting.rb', line 94

def process(value)
  # rubocop:disable Lint/DuplicateBranch
  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
  # rubocop:enable Lint/DuplicateBranch
end