Class: Ronin::Core::Params::Types::Float

Inherits:
Numeric
  • Object
show all
Defined in:
lib/ronin/core/params/types/float.rb

Overview

Represents a true/false param.

Instance Attribute Summary

Attributes inherited from Numeric

#max, #min, #range

Instance Method Summary collapse

Methods inherited from Numeric

#initialize

Constructor Details

This class inherits a constructor from Ronin::Core::Params::Types::Numeric

Instance Method Details

#coerce(value) ⇒ ::Float

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerces a value into a Float value.

Parameters:

  • value (::Float, ::String, #to_f, Object)

    The value to coerce.

Returns:

  • (::Float)

    The coerced Float value.

Raises:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ronin/core/params/types/float.rb', line 45

def coerce(value)
  case value
  when ::Float
    super(value)
  when ::String
    if value =~ /\A[+-]?\d+(?:\.\d+)?\z/
      super(value.to_f)
    else
      raise(ValidationError,"value contains non-numeric characters (#{value.inspect})")
    end
  else
    if value.respond_to?(:to_f)
      super(value.to_f)
    else
      raise(ValidationError,"value does not define a #to_f method (#{value.inspect})")
    end
  end
end