class OptParseValidator::OptIntegerRange
Implementation of the Integer Range Option
Public Instance Methods
append_help_messages()
click to toggle source
@return [ Void ]
Calls superclass method
OptParseValidator::OptBase#append_help_messages
# File lib/opt_parse_validator/opts/integer_range.rb, line 7 def append_help_messages option << "Range separator to use: '#{separator}'" super end
separator()
click to toggle source
@return [ String ]
# File lib/opt_parse_validator/opts/integer_range.rb, line 30 def separator attrs[:separator] || '-' end
validate(value)
click to toggle source
@param [ String ] value
@return [ Range ]
Calls superclass method
OptParseValidator::OptBase#validate
# File lib/opt_parse_validator/opts/integer_range.rb, line 16 def validate(value) a = super(value).split(separator) raise Error, "Incorrect number of ranges found: #{a.size}, should be 2" unless a.size == 2 first_integer = a.first.to_i last_integer = a.last.to_i raise Error, 'Argument is not a valid integer range' unless first_integer.to_s == a.first && last_integer.to_s == a.last (first_integer..last_integer) end