Class: TokenArray
- Inherits:
-
Array
- Object
- Array
- TokenArray
- Defined in:
- lib/mediacloth/mediawikilexer.rb
Instance Method Summary collapse
- #<<(token) ⇒ Object
- #append_pending(text) ⇒ Object
-
#initialize(lexer) ⇒ TokenArray
constructor
A new instance of TokenArray.
- #to_s ⇒ Object
Constructor Details
#initialize(lexer) ⇒ TokenArray
Returns a new instance of TokenArray.
30 31 32 |
# File 'lib/mediacloth/mediawikilexer.rb', line 30 def initialize(lexer) @lexer = lexer end |
Instance Method Details
#<<(token) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/mediacloth/mediawikilexer.rb', line 34 def <<(token) if @lexer.tokens.last && (@lexer.tokens.last[3].nil? || @lexer.tokens.last[3] == 0) @lexer.tokens.last[3] = @lexer.cursor - @lexer.tokens.last[2] end token[2] = @lexer.cursor super(token) end |
#append_pending(text) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/mediacloth/mediawikilexer.rb', line 42 def append_pending(text) if @lexer.tokens.last && @lexer.tokens.last[3].nil? @lexer.tokens.last[3] = text.idx - @lexer.tokens.last[2] end token = [:TEXT, text, text.idx, text.length] push(token) end |
#to_s ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/mediacloth/mediawikilexer.rb', line 50 def to_s string_copy = "" each do |token| string_copy << "#{token[0..1]}[#{token[2]}, #{token[3]}]" end string_copy end |