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.



531
532
533
534
535
# File 'lib/tbmx.rb', line 531

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

Instance Attribute Details

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



525
526
527
# File 'lib/tbmx.rb', line 525

def paragraphs
  @paragraphs
end

#split_tokensObject (readonly)

Returns the value of attribute split_tokens.



525
526
527
# File 'lib/tbmx.rb', line 525

def split_tokens
  @split_tokens
end

#textObject (readonly)

Returns the value of attribute text.



525
526
527
# File 'lib/tbmx.rb', line 525

def text
  @text
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



525
526
527
# File 'lib/tbmx.rb', line 525

def tokenizer
  @tokenizer
end

Instance Method Details

#parseObject



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

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

#to_htmlObject



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

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

#tokensObject



527
528
529
# File 'lib/tbmx.rb', line 527

def tokens
  tokenizer.tokens
end