class Wpxf::IntegerOption
An integer option.
Attributes
max[RW]
@return [Integer, nil] the highest valid value.
min[RW]
@return [Integer, nil] the lowest valid value.
Public Class Methods
new(attrs)
click to toggle source
Initializes a named option. @param attrs an object containing the following values
* *name*: the name of the option (required) * *desc*: the description of the option (required) * *required*: whether or not the option is required * *default*: the default value of the option * *advanced*: whether or not this is an advanced option * *evasion*: whether or not this is an evasion option * *enums*: the list of potential valid values * *regex*: regex to validate the option value * *min*: the lowest valid value * *max*: the highest valid value
Calls superclass method
# File lib/wpxf/core/opts/integer_option.rb, line 19 def initialize(attrs) super self.min = attrs[:min].to_i unless attrs[:min].nil? self.max = attrs[:max].to_i unless attrs[:max].nil? end
Public Instance Methods
meets_max_requirement?(value)
click to toggle source
@param value the value to validate. @return [Boolean] true if the value meets the maximum valid value
requirement.
# File lib/wpxf/core/opts/integer_option.rb, line 53 def meets_max_requirement?(value) max.nil? || (normalize(value) <= max) end
meets_min_requirement?(value)
click to toggle source
@param value the value to validate. @return [Boolean] true if the value meets the minimum valid value
requirement.
# File lib/wpxf/core/opts/integer_option.rb, line 46 def meets_min_requirement?(value) min.nil? || (normalize(value) >= min) end
normalize(value)
click to toggle source
@param value the value to normalize. @return [Integer] a normalized value to conform with the type that
the option is conveying.
# File lib/wpxf/core/opts/integer_option.rb, line 29 def normalize(value) if value.to_s.match?(/^0x[a-fA-F\d]+$/) value.to_i(16) else value.to_i end end
valid?(value)
click to toggle source
Check if the specified value is valid in the context of this option. @param value the value to validate. @return [Boolean] true if valid.
Calls superclass method
# File lib/wpxf/core/opts/integer_option.rb, line 60 def valid?(value) return true if value.nil? && !required? return false unless valid_integer?(value) return false unless meets_min_requirement?(value) return false unless meets_max_requirement?(value) super end
valid_integer?(value)
click to toggle source
@param value the value to validate. @return [Boolean] true if the value is a valid integer.
# File lib/wpxf/core/opts/integer_option.rb, line 39 def valid_integer?(value) value && !value.to_s.match(/^0x[0-9a-fA-F]+$|^-?\d+$/).nil? end