Class: SyntaxTree::CSS::Selectors::TokenEnumerator
- Inherits:
-
Object
- Object
- SyntaxTree::CSS::Selectors::TokenEnumerator
- Defined in:
- lib/syntax_tree/css/selectors.rb
Overview
A custom enumerator around the list of tokens. This allows us to save a reference to where we are when we’re looking at the stream and rollback to that point if we need to.
Defined Under Namespace
Classes: Rollback
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(tokens) ⇒ TokenEnumerator
constructor
A new instance of TokenEnumerator.
- #next ⇒ Object
- #peek ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(tokens) ⇒ TokenEnumerator
Returns a new instance of TokenEnumerator.
23 24 25 26 |
# File 'lib/syntax_tree/css/selectors.rb', line 23 def initialize(tokens) @tokens = tokens @index = 0 end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
21 22 23 |
# File 'lib/syntax_tree/css/selectors.rb', line 21 def index @index end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
21 22 23 |
# File 'lib/syntax_tree/css/selectors.rb', line 21 def tokens @tokens end |
Instance Method Details
#next ⇒ Object
28 29 30 |
# File 'lib/syntax_tree/css/selectors.rb', line 28 def next @tokens[@index].tap { @index += 1} end |
#peek ⇒ Object
32 33 34 |
# File 'lib/syntax_tree/css/selectors.rb', line 32 def peek @tokens[@index] end |
#transaction ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/syntax_tree/css/selectors.rb', line 36 def transaction saved = @index yield rescue Rollback @index = saved nil end |