Class: Rubycli::Arguments::TokenStream
- Inherits:
-
Object
- Object
- Rubycli::Arguments::TokenStream
- Defined in:
- lib/rubycli/arguments/token_stream.rb
Overview
Lightweight mutable cursor over CLI tokens.
Instance Method Summary collapse
- #advance(count = 1) ⇒ Object
- #consume ⇒ Object
- #consume_remaining ⇒ Object
- #current ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(tokens) ⇒ TokenStream
constructor
A new instance of TokenStream.
- #peek(offset = 1) ⇒ Object
Constructor Details
#initialize(tokens) ⇒ TokenStream
Returns a new instance of TokenStream.
7 8 9 10 |
# File 'lib/rubycli/arguments/token_stream.rb', line 7 def initialize(tokens) @tokens = Array(tokens).dup @index = 0 end |
Instance Method Details
#advance(count = 1) ⇒ Object
20 21 22 |
# File 'lib/rubycli/arguments/token_stream.rb', line 20 def advance(count = 1) @index += count end |
#consume ⇒ Object
24 25 26 27 28 |
# File 'lib/rubycli/arguments/token_stream.rb', line 24 def consume value = current advance value end |
#consume_remaining ⇒ Object
30 31 32 33 34 |
# File 'lib/rubycli/arguments/token_stream.rb', line 30 def consume_remaining remaining = @tokens[@index..] || [] @index = @tokens.length remaining end |
#current ⇒ Object
12 13 14 |
# File 'lib/rubycli/arguments/token_stream.rb', line 12 def current @tokens[@index] end |
#finished? ⇒ Boolean
36 37 38 |
# File 'lib/rubycli/arguments/token_stream.rb', line 36 def finished? @index >= @tokens.length end |
#peek(offset = 1) ⇒ Object
16 17 18 |
# File 'lib/rubycli/arguments/token_stream.rb', line 16 def peek(offset = 1) @tokens[@index + offset] end |