Class: GovukTechDocs::TableOfContents::HeadingTree
- Inherits:
-
Object
- Object
- GovukTechDocs::TableOfContents::HeadingTree
- Defined in:
- lib/govuk_tech_docs/table_of_contents/heading_tree.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#heading ⇒ Object
Returns the value of attribute heading.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #depth ⇒ Object
-
#initialize(parent: nil, heading: nil, children: []) ⇒ HeadingTree
constructor
A new instance of HeadingTree.
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
#children ⇒ Object
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 |
#heading ⇒ Object
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 |
#parent ⇒ Object
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 |
#depth ⇒ Object
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 |