Class: OptParseValidator::OptIntegerRange
- Defined in:
- lib/opt_parse_validator/opts/integer_range.rb
Overview
Implementation of the Integer Range Option
Instance Attribute Summary
Attributes inherited from OptBase
Instance Method Summary collapse
Methods inherited from OptBase
#advanced?, #alias?, #choices, #default, #help_message_for_default, #help_messages, #initialize, #normalize, #required?, #required_unless, #to_long, #to_s, #to_sym, #value_if_empty
Constructor Details
This class inherits a constructor from OptParseValidator::OptBase
Instance Method Details
#append_help_messages ⇒ Void
5 6 7 8 9 |
# File 'lib/opt_parse_validator/opts/integer_range.rb', line 5 def option << "Range separator to use: '#{separator}'" super end |
#separator ⇒ String
28 29 30 |
# File 'lib/opt_parse_validator/opts/integer_range.rb', line 28 def separator attrs[:separator] || '-' end |
#validate(value) ⇒ Range
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/opt_parse_validator/opts/integer_range.rb', line 14 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 |