Class: Dynamoid::TypeCasting::IntegerTypeCaster

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dynamoid/type_casting.rb', line 74

def process(value)
  # rubocop:disable Lint/DuplicateBranch
  if value == true
    1
  elsif value == false
    0
  elsif value.is_a?(String) && value.blank?
    nil
  elsif value.is_a?(Float) && !value.finite?
    nil
  elsif !value.respond_to?(:to_i)
    nil
  else
    value.to_i
  end
  # rubocop:enable Lint/DuplicateBranch
end