Class: TokenString

Inherits:
String show all
Defined in:
lib/mediacloth/mediawikilexer.rb

Overview

Class for storing text tokens data - index and text

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#is_empty_token?

Constructor Details

#initialize(lexer, text = '') ⇒ TokenString

Returns a new instance of TokenString.



13
14
15
16
17
# File 'lib/mediacloth/mediawikilexer.rb', line 13

def initialize(lexer, text = '')
    @lexer = lexer
    @idx = 0
    super(text)
end

Instance Attribute Details

#idxObject (readonly)

Returns the value of attribute idx.



11
12
13
# File 'lib/mediacloth/mediawikilexer.rb', line 11

def idx
  @idx
end

Instance Method Details

#<<(pending_text) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/mediacloth/mediawikilexer.rb', line 19

def <<(pending_text)
    # If TokenString.length is 0 and we are pushing some text
    # than in this moment we can retreive this tokes's index
    if length == 0
        @idx = @lexer.cursor
    end
    super(pending_text)
end