Class: Ronin::Core::Params::Types::Numeric
- Defined in:
- lib/ronin/core/params/types/numeric.rb
Overview
Represents a true/false param.
Instance Attribute Summary collapse
-
#max ⇒ ::Integer?
readonly
private
The optional maximum value.
-
#min ⇒ ::Integer?
readonly
private
The optional minimum value.
-
#range ⇒ Range?
readonly
private
The optional range of acceptable numbers.
Instance Method Summary collapse
-
#coerce(value) ⇒ ::Integer, ::Float
abstract
Validates a numeric value.
-
#initialize(min: nil, max: nil, range: nil) ⇒ Numeric
constructor
Initializes the numeric value.
Constructor Details
#initialize(min: nil, max: nil, range: nil) ⇒ Numeric
Initializes the numeric value.
63 64 65 66 67 |
# File 'lib/ronin/core/params/types/numeric.rb', line 63 def initialize(min: nil, max: nil, range: nil) @min = min @max = max @range = range end |
Instance Attribute Details
#max ⇒ ::Integer? (readonly)
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.
The optional maximum value.
42 43 44 |
# File 'lib/ronin/core/params/types/numeric.rb', line 42 def max @max end |
#min ⇒ ::Integer? (readonly)
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.
The optional minimum value.
35 36 37 |
# File 'lib/ronin/core/params/types/numeric.rb', line 35 def min @min end |
#range ⇒ Range? (readonly)
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.
The optional range of acceptable numbers.
49 50 51 |
# File 'lib/ronin/core/params/types/numeric.rb', line 49 def range @range end |
Instance Method Details
#coerce(value) ⇒ ::Integer, ::Float
Validates a numeric value.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ronin/core/params/types/numeric.rb', line 84 def coerce(value) if @range unless @range.include?(value) raise(ValidationError,"value is not within the range of acceptable values #{@range.begin}-#{@range.end} (#{value.inspect})") end else if @min && (value < @min) raise(ValidationError,"value is below minimum value of #{@min} (#{value.inspect})") end if @max && (value > @max) raise(ValidationError,"value is above maximum value of #{@max} (#{value.inspect})") end end return value end |