Class: BetterHtml::Tokenizer::TokenArray
- Inherits:
-
Object
- Object
- BetterHtml::Tokenizer::TokenArray
- Defined in:
- lib/better_html/tokenizer/token_array.rb
Instance Method Summary collapse
- #any? ⇒ Boolean
- #current ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(list) ⇒ TokenArray
constructor
A new instance of TokenArray.
- #last ⇒ Object
- #pop ⇒ Object
- #shift ⇒ Object
- #size ⇒ Object
- #trim(type) ⇒ Object
Constructor Details
#initialize(list) ⇒ TokenArray
Returns a new instance of TokenArray.
6 7 8 9 10 |
# File 'lib/better_html/tokenizer/token_array.rb', line 6 def initialize(list) @list = list @current = 0 @last = @list.size end |
Instance Method Details
#any? ⇒ Boolean
37 38 39 |
# File 'lib/better_html/tokenizer/token_array.rb', line 37 def any? !empty? end |
#current ⇒ Object
41 42 43 |
# File 'lib/better_html/tokenizer/token_array.rb', line 41 def current @list[@current] unless empty? end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/better_html/tokenizer/token_array.rb', line 33 def empty? size <= 0 end |
#last ⇒ Object
45 46 47 |
# File 'lib/better_html/tokenizer/token_array.rb', line 45 def last @list[@last - 1] unless empty? end |
#pop ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/better_html/tokenizer/token_array.rb', line 20 def pop raise "no tokens left to pop" if empty? item = @list[@last - 1] @last -= 1 item end |
#shift ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/better_html/tokenizer/token_array.rb', line 12 def shift raise "no tokens left to shift" if empty? item = @list[@current] @current += 1 item end |
#size ⇒ Object
49 50 51 |
# File 'lib/better_html/tokenizer/token_array.rb', line 49 def size @last - @current end |
#trim(type) ⇒ Object
28 29 30 31 |
# File 'lib/better_html/tokenizer/token_array.rb', line 28 def trim(type) shift while current&.type == type pop while last&.type == type end |