Class: Aliyun::Log::Record::TypeCasting::BigDecimalType

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



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/aliyun/log/record/type_casting.rb', line 132

def cast(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