Class: GovukTechDocs::TableOfContents::HeadingTreeBuilder
- Inherits:
-
Object
- Object
- GovukTechDocs::TableOfContents::HeadingTreeBuilder
- Defined in:
- lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb
Instance Method Summary collapse
-
#initialize(headings) ⇒ HeadingTreeBuilder
constructor
A new instance of HeadingTreeBuilder.
- #tree ⇒ Object
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
#tree ⇒ Object
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 |