Class: Command::NumberArgument

Inherits:
Argument
  • Object
show all
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

Attributes inherited from Argument

#name

Instance Method Summary collapse

Methods inherited from Argument

#basis, #check_present, #consume, #consume_hash, #initialize, #match_terms, #names, #omittable?, register, #required?, #subject_requirements

Constructor Details

This class inherits a constructor from Command::Argument

Instance Method Details

#complete(terms, prefix, subject) ⇒ Object



162
163
164
165
# File 'lib/command-set/arguments.rb', line 162

def complete(terms, prefix, subject)
  return [] unless validate(prefix, subject)
  return [prefix]
end

#parse(subject, term) ⇒ Object



175
176
177
# File 'lib/command-set/arguments.rb', line 175

def parse(subject, term)
  return term.to_i
end

#validate(term, subject) ⇒ Object



167
168
169
170
171
172
173
# File 'lib/command-set/arguments.rb', line 167

def validate(term, subject)
  value = parse(subject, term)
  range = basis(subject)
  return false if not range.nil? and not range.include?(value) 
  return true if %r{^0(\D.*)?} =~ term
  return value != 0
end