Class: GovukTechDocs::TableOfContents::HeadingTree

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent: nil, heading: nil, children: []) ⇒ HeadingTree

Returns a new instance of HeadingTree.



6
7
8
9
10
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree.rb', line 6

def initialize(parent: nil, heading: nil, children: [])
  @parent = parent
  @heading = heading
  @children = children
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree.rb', line 4

def children
  @children
end

#headingObject

Returns the value of attribute heading.



4
5
6
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree.rb', line 4

def heading
  @heading
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree.rb', line 4

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
24
# File 'lib/govuk_tech_docs/table_of_contents/heading_tree.rb', line 20

def ==(other)
  heading == other.heading &&
    children.length == other.children.length &&
    children.map.with_index { |child, index| child == other.children[index] }.all?
end

#depthObject



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

def depth
  if parent
    parent.depth + 1
  else
    1
  end
end