Class: StrongerParameters::FloatConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::FloatConstraint
- Defined in:
- lib/stronger_parameters/constraints/float_constraint.rb
Instance Method Summary collapse
Methods inherited from Constraint
#&, #==, #required, #required?, #|
Instance Method Details
#value(v) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/stronger_parameters/constraints/float_constraint.rb', line 7 def value(v) if v.is_a?(Float) return v elsif v.is_a?(String) && v =~ /\A-?\d+\.\d+\Z/ return v.to_f end StrongerParameters::InvalidValue.new(v, "must be a float") end |