Class: TBMX::Parser

Inherits:
ParserNode show all
Defined in:
lib/tbmx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



485
486
487
488
489
# File 'lib/tbmx.rb', line 485

def initialize(text)
  @text = text
  @tokenizer = Tokenizer.new text
  parse
end

Instance Attribute Details

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



479
480
481
# File 'lib/tbmx.rb', line 479

def paragraphs
  @paragraphs
end

#split_tokensObject (readonly)

Returns the value of attribute split_tokens.



479
480
481
# File 'lib/tbmx.rb', line 479

def split_tokens
  @split_tokens
end

#textObject (readonly)

Returns the value of attribute text.



479
480
481
# File 'lib/tbmx.rb', line 479

def text
  @text
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



479
480
481
# File 'lib/tbmx.rb', line 479

def tokenizer
  @tokenizer
end

Instance Method Details

#parseObject



491
492
493
494
# File 'lib/tbmx.rb', line 491

def parse
  @split_tokens = tokens.split {|token| token.class == EmptyNewlinesToken}
  @paragraphs = @split_tokens.map {|split_tokens| ParagraphParser.new split_tokens}
end

#to_htmlObject



496
497
498
# File 'lib/tbmx.rb', line 496

def to_html
  paragraphs.map(&:to_html).join "\n"
end

#tokensObject



481
482
483
# File 'lib/tbmx.rb', line 481

def tokens
  tokenizer.tokens
end