class HashCast::Casters::FloatCaster
Public Class Methods
cast(value, attr_name, options = {})
click to toggle source
# File lib/hashcast/casters/float_caster.rb, line 3 def self.cast(value, attr_name, options = {}) return value if value.is_a?(Float) return cast_string(value) if value.is_a?(String) raise HashCast::Errors::CastingError, "#{value} should be a float" end
cast_string(value)
click to toggle source
# File lib/hashcast/casters/float_caster.rb, line 9 def self.cast_string(value) Float(value) rescue ArgumentError => e raise HashCast::Errors::CastingError, "#{value} is invalid float" end