Class: Command::MultiArgument
Overview
Consumes multiple words as dictated by the block used to create the argument. A little complex, but powerful. For use, see StandardCommands::Set
Instance Attribute Summary
Attributes inherited from Argument
#name
Instance Method Summary
collapse
Methods inherited from Argument
#basis, #check_present, #consume_hash, #names, #parse, register, #required?, #subject_requirements
Constructor Details
#initialize(name, block) ⇒ MultiArgument
Returns a new instance of MultiArgument.
482
483
484
485
486
|
# File 'lib/command-set/arguments.rb', line 482
def initialize(name, block)
raise TypeError, "Block arity is #{prok.arity}, not 2" unless block.arity == 2
super(name,nil)
@process = proc &block
end
|
Instance Method Details
#complete(terms, prefix, subject) ⇒ Object
488
489
490
|
# File 'lib/command-set/arguments.rb', line 488
def complete(terms, prefix, subject)
return @process[[*prefix], subject]
end
|
#consume(subject, arguments) ⇒ Object
496
497
498
499
500
501
502
503
504
505
506
507
508
|
# File 'lib/command-set/arguments.rb', line 496
def consume(subject, arguments)
value = []
until arguments.empty? do
trying = arguments.shift
if(validate(value + [trying], subject))
value << trying
else
arguments.unshift(trying)
break
end
end
return {@name => value}
end
|
#match_terms(subject, terms, arguments) ⇒ Object
514
515
516
517
518
519
520
521
522
|
# File 'lib/command-set/arguments.rb', line 514
def match_terms(subject, terms, arguments)
validated = validate(terms.first, subject)
if(validated)
terms.shift
else
arguments.shift
end
return true
end
|
#omittable? ⇒ Boolean
510
511
512
|
# File 'lib/command-set/arguments.rb', line 510
def omittable?
true
end
|
#validate(terms, subject) ⇒ Object
492
493
494
|
# File 'lib/command-set/arguments.rb', line 492
def validate(terms, subject)
return (not @process[[*terms.dup], subject].empty?)
end
|