Sha256: 205075e9dcbf79651218bed654ebd69fb20f1c8eb1644d71acf8af809892af65
Contents?: true
Size: 836 Bytes
Versions: 5
Compression:
Stored size: 836 Bytes
Contents
module GovukTechDocs module TableOfContents class HeadingTreeBuilder def initialize(headings) @headings = headings @tree = HeadingTree.new @pointer = @tree end def tree @headings.each do |heading| move_to_depth(heading.size) @pointer.children << HeadingTree.new(parent: @pointer, heading:) end @tree end private def move_to_depth(depth) if depth > @pointer.depth @pointer = @pointer.children.last if depth > @pointer.depth @pointer.children << HeadingTree.new(parent: @pointer) move_to_depth(depth) end end if depth < @pointer.depth @pointer = @pointer.parent move_to_depth(depth) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems