Class: TBMX::Parser
- Inherits:
-
ParserNode
- Object
- ParserNode
- TBMX::Parser
- Defined in:
- lib/tbmx.rb
Instance Attribute Summary collapse
-
#paragraphs ⇒ Object
readonly
Returns the value of attribute paragraphs.
-
#split_tokens ⇒ Object
readonly
Returns the value of attribute split_tokens.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#tokenizer ⇒ Object
readonly
Returns the value of attribute tokenizer.
Instance Method Summary collapse
-
#initialize(text) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #to_html ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(text) ⇒ Parser
Returns a new instance of Parser.
547 548 549 550 551 |
# File 'lib/tbmx.rb', line 547 def initialize(text) @text = text @tokenizer = Tokenizer.new text parse end |
Instance Attribute Details
#paragraphs ⇒ Object (readonly)
Returns the value of attribute paragraphs.
541 542 543 |
# File 'lib/tbmx.rb', line 541 def paragraphs @paragraphs end |
#split_tokens ⇒ Object (readonly)
Returns the value of attribute split_tokens.
541 542 543 |
# File 'lib/tbmx.rb', line 541 def split_tokens @split_tokens end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
541 542 543 |
# File 'lib/tbmx.rb', line 541 def text @text end |
#tokenizer ⇒ Object (readonly)
Returns the value of attribute tokenizer.
541 542 543 |
# File 'lib/tbmx.rb', line 541 def tokenizer @tokenizer end |
Instance Method Details
#parse ⇒ Object
553 554 555 556 |
# File 'lib/tbmx.rb', line 553 def parse @split_tokens = tokens.split {|token| token.class == EmptyNewlinesToken} @paragraphs = @split_tokens.map {|split_tokens| ParagraphParser.new split_tokens} end |
#to_html ⇒ Object
558 559 560 |
# File 'lib/tbmx.rb', line 558 def to_html paragraphs.map(&:to_html).join "\n" end |
#tokens ⇒ Object
543 544 545 |
# File 'lib/tbmx.rb', line 543 def tokens tokenizer.tokens end |