Class: Aliyun::Log::Record::TypeCasting::FloatType

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



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/aliyun/log/record/type_casting.rb', line 152

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