Class: Pablo::Command
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Parser
#desc, #last_match, #longdesc, #names, #usage
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Command
constructor
A new instance of Command.
-
#names_to_rex ⇒ Object
Format a command’s names to be used in a Regexp.
-
#names_to_user ⇒ Object
Format a command’s names to be displayed to the user.
- #parse(args) ⇒ Object
Methods inherited from Parser
Constructor Details
#initialize(*args, &block) ⇒ Command
Returns a new instance of Command.
28 29 30 31 |
# File 'lib/pablo/command.rb', line 28 def initialize *args, &block super(*args, &block) @opts[:consume_all] = @pablo.consume_all? if @opts[:consume_all].nil? end |
Instance Method Details
#names_to_rex ⇒ Object
Format a command’s names to be used in a Regexp.
64 65 66 |
# File 'lib/pablo/command.rb', line 64 def names_to_rex Regexp.new(names_to_user) end |
#names_to_user ⇒ Object
Format a command’s names to be displayed to the user.
58 59 60 |
# File 'lib/pablo/command.rb', line 58 def names_to_user @names.collect(&:to_s).join('|') end |
#parse(args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pablo/command.rb', line 33 def parse args name = nil idx = args.zip((0...args.length).to_a).find_index { |(a,i)| verifies?(a,i) and (name = matches?(a)) } unless idx.nil? args.consume idx args.slice idx @pablo.commands[name] = true unless returning(consume?(name, args)) { run?(args) } args.consume_all if @toplevel and @opts[:consume_all] end args.unslice true else false end end |