Class: OpenActive::Validators::FloatValidator

Inherits:
BaseValidator show all
Defined in:
lib/openactive/validators/float_validator.rb

Instance Method Summary collapse

Methods inherited from BaseValidator

get_validator

Instance Method Details

#coerce(value) ⇒ float

Coerce given value to the type the validator is validating against. PLEASE NOTE: no checks are performed on the given value. It is therefore recommended to call the “run” method first before this.

Parameters:

  • value (mixed)

    The value to coerce.

Returns:

  • (float)

    The coerced value



10
11
12
# File 'lib/openactive/validators/float_validator.rb', line 10

def coerce(value)
  value.to_f
end

#run(value) ⇒ Boolean

Run validation on the given value.

Parameters:

  • value (mixed)

    The value to validate.

Returns:

  • (Boolean)

    Whether validation passes or not.



18
19
20
21
22
23
# File 'lib/openactive/validators/float_validator.rb', line 18

def run(value)
  Float(value)
  true
rescue ArgumentError => _e
  false
end