Sha256: c3173e7665e99cbf97146d8e7c6c81a31fd8f9f903866dcad208fc4ba8ed744f
Contents?: true
Size: 844 Bytes
Versions: 58
Compression:
Stored size: 844 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: 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
58 entries across 58 versions & 2 rubygems