Class: Teepee::Parser

Inherits:
ParserNode show all
Defined in:
lib/teepee/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



62
63
64
65
66
# File 'lib/teepee/parser.rb', line 62

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

Instance Attribute Details

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



56
57
58
# File 'lib/teepee/parser.rb', line 56

def paragraphs
  @paragraphs
end

#split_tokensObject (readonly)

Returns the value of attribute split_tokens.



56
57
58
# File 'lib/teepee/parser.rb', line 56

def split_tokens
  @split_tokens
end

#textObject (readonly)

Returns the value of attribute text.



56
57
58
# File 'lib/teepee/parser.rb', line 56

def text
  @text
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



56
57
58
# File 'lib/teepee/parser.rb', line 56

def tokenizer
  @tokenizer
end

Instance Method Details

#parseObject



68
69
70
71
# File 'lib/teepee/parser.rb', line 68

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

#to_htmlObject



73
74
75
# File 'lib/teepee/parser.rb', line 73

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

#tokensObject



58
59
60
# File 'lib/teepee/parser.rb', line 58

def tokens
  tokenizer.tokens
end