Class: Pablo::Token
- Includes:
- Helpers
- Defined in:
- lib/pablo/token.rb
Instance Attribute Summary
Attributes inherited from Parser
#desc, #last_match, #longdesc, #names, #usage
Instance Method Summary collapse
-
#names_to_rex ⇒ Object
Format a token’s names to be used in a Regexp.
-
#names_to_user ⇒ Object
Format a token’s names to be displayed to the user.
- #parse(args) ⇒ Object
Methods inherited from Parser
Constructor Details
This class inherits a constructor from Pablo::Parser
Instance Method Details
#names_to_rex ⇒ Object
Format a token’s names to be used in a Regexp
59 60 61 |
# File 'lib/pablo/token.rb', line 59 def names_to_rex Regexp.new(names_to_user) end |
#names_to_user ⇒ Object
Format a token’s names to be displayed to the user.
53 54 55 |
# File 'lib/pablo/token.rb', line 53 def names_to_user @names.collect(&:to_s).join('|') end |
#parse(args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pablo/token.rb', line 30 def parse args idx = args.zip((0...args.length).to_a).find_index { |(a,i)| verifies?(a,i) } unless idx.nil? name = @names[0] args.slice idx @names.each { |n| @pablo.tokens[n] = true } unless name.nil? if returning(consume?(name, args)) { run?(args) } @names[1..-1].each { |n| @pablo.tokens[n] = @pablo.tokens[@names[0]] } end args.unslice true else false end end |