Class: Tocer::Builder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tocer/builder.rb

Overview

Builds table of contents for a Markdown document.

Constant Summary collapse

CODE_BLOCK_PUNCTUATION =
"```"

Instance Method Summary collapse

Constructor Details

#initialize(comment_block: Elements::CommentBlock.new, transformer: Transformers::Finder.new) ⇒ Builder

Returns a new instance of Builder.



14
15
16
17
18
19
# File 'lib/tocer/builder.rb', line 14

def initialize comment_block: Elements::CommentBlock.new, transformer: Transformers::Finder.new
  @comment_block = comment_block
  @transformer = transformer
  @url_count = Hash.new 0
  @code_block = false
end

Instance Method Details

#call(lines, label: Container[:configuration].label) ⇒ Object



23
24
25
26
27
28
# File 'lib/tocer/builder.rb', line 23

def call lines, label: Container[:configuration].label
  return "" if headers(lines).empty?

  url_count.clear
  assemble(lines, label).join
end

#unbuildable?(lines) ⇒ Boolean

Returns:

  • (Boolean)


21
# File 'lib/tocer/builder.rb', line 21

def unbuildable?(lines) = comment_block.empty?(lines) && headers(lines).empty?