class BetterHtml::Tokenizer::TokenArray
Public Class Methods
new(list)
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 4 def initialize(list) @list = list @current = 0 @last = @list.size end
Public Instance Methods
any?()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 37 def any? !empty? end
current()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 41 def current @list[@current] unless empty? end
empty?()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 33 def empty? size <= 0 end
last()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 45 def last @list[@last - 1] unless empty? end
pop()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 17 def pop raise RuntimeError, 'no tokens left to pop' if empty? item = @list[@last - 1] @last -= 1 item end
shift()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 10 def shift raise RuntimeError, 'no tokens left to shift' if empty? item = @list[@current] @current += 1 item end
size()
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 49 def size @last - @current end
trim(type)
click to toggle source
# File lib/better_html/tokenizer/token_array.rb, line 24 def trim(type) while current&.type == type shift end while last&.type == type pop end end