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.



545
546
547
548
549
# File 'lib/tbmx.rb', line 545

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

Instance Attribute Details

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



539
540
541
# File 'lib/tbmx.rb', line 539

def paragraphs
  @paragraphs
end

#split_tokensObject (readonly)

Returns the value of attribute split_tokens.



539
540
541
# File 'lib/tbmx.rb', line 539

def split_tokens
  @split_tokens
end

#textObject (readonly)

Returns the value of attribute text.



539
540
541
# File 'lib/tbmx.rb', line 539

def text
  @text
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



539
540
541
# File 'lib/tbmx.rb', line 539

def tokenizer
  @tokenizer
end

Instance Method Details

#parseObject



551
552
553
554
# File 'lib/tbmx.rb', line 551

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

#to_htmlObject



556
557
558
# File 'lib/tbmx.rb', line 556

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

#tokensObject



541
542
543
# File 'lib/tbmx.rb', line 541

def tokens
  tokenizer.tokens
end