Class: Aliyun::Log::Record::TypeCasting::IntegerType

Inherits:
Value
  • Object
show all
Defined in:
lib/aliyun/log/record/type_casting.rb

Instance Method Summary collapse

Methods inherited from Value

#dump, #initialize

Constructor Details

This class inherits a constructor from Aliyun::Log::Record::TypeCasting::Value

Instance Method Details

#cast(value) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/aliyun/log/record/type_casting.rb', line 114

def cast(value)
  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
end