Class: Command::NumberArgument
- Defined in:
- lib/command-set/arguments.rb
Overview
Input has to be a number, in the range passed to create the argument
Instance Attribute Summary collapse
-
#range ⇒ Object
Returns the value of attribute range.
Attributes inherited from Argument
Instance Method Summary collapse
- #complete(prefix, subject) ⇒ Object
-
#initialize(name, range = nil) ⇒ NumberArgument
constructor
A new instance of NumberArgument.
- #parse(subject, term) ⇒ Object
- #validate(term, subject) ⇒ Object
Methods inherited from Argument
#check_present, #consume, #consume_hash, #match_terms, #omittable?, register, #required?
Constructor Details
#initialize(name, range = nil) ⇒ NumberArgument
Returns a new instance of NumberArgument.
126 127 128 129 |
# File 'lib/command-set/arguments.rb', line 126 def initialize(name, range=nil) super(name) @range = range end |
Instance Attribute Details
#range ⇒ Object
Returns the value of attribute range.
131 132 133 |
# File 'lib/command-set/arguments.rb', line 131 def range @range end |
Instance Method Details
#complete(prefix, subject) ⇒ Object
133 134 135 136 |
# File 'lib/command-set/arguments.rb', line 133 def complete(prefix, subject) return [] unless validate(prefix, subject) return [prefix] end |
#parse(subject, term) ⇒ Object
145 146 147 |
# File 'lib/command-set/arguments.rb', line 145 def parse(subject, term) @value = term.to_i end |
#validate(term, subject) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/command-set/arguments.rb', line 138 def validate(term, subject) value = parse(subject, term) return false if not range.nil? and not range.include?(value) return true if %r{^0(\D.*)?} =~ term return value != 0 end |