class Morf::Casters::FloatCaster

Public Class Methods

cast(value, attr_name, options = {}) click to toggle source
# File lib/morf/casters/float_caster.rb, line 2
def self.cast(value, attr_name, options = {})
  if value.is_a?(Float)
    value
  elsif value.is_a?(String)
    begin
      Float(value)
    rescue ArgumentError => e
      raise Morf::Errors::CastingError, "is invalid float"
    end
  else
    raise Morf::Errors::CastingError, "should be a float"
  end
end