Class: Numeric

Inherits:
Object show all
Defined in:
lib/ripple/core_ext/casting.rb

Class Method Summary collapse

Class Method Details

.ripple_cast(value) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ripple/core_ext/casting.rb', line 32

def self.ripple_cast(value)
  return nil if value.blank?
  raise Ripple::PropertyTypeMismatch.new(self,value) unless value.respond_to?(:to_i) && value.respond_to?(:to_f)
  float_value = value.to_f
  int_value = value.to_i
  float_value == int_value ? int_value : float_value
end