Class: GovukTechDocs::TableOfContents::HeadingTreeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(headings) ⇒ HeadingTreeBuilder

Returns a new instance of HeadingTreeBuilder.



4
5
6
7
8
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb', line 4

def initialize(headings)
  @headings = headings
  @tree = HeadingTree.new
  @pointer = @tree
end

Instance Method Details

#treeObject



10
11
12
13
14
15
16
17
18
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb', line 10

def tree
  @headings.each do |heading|
    move_to_depth(heading.size)

    @pointer.children << HeadingTree.new(parent: @pointer, heading:)
  end

  @tree
end