Module: Infoboxer::Navigation::Sections::Node

Included in:
Tree::Node
Defined in:
lib/infoboxer/navigation/sections.rb

Overview

Part of Infoboxer::Navigation::Sections navigation, allowing each node to know exact list of sections it contained in.

See also parent module documentation.

Instance Method Summary collapse

Instance Method Details

#in_sectionsTree::Nodes<Section>

List of sections current node contained in (bottom-to-top: smallest section first).

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/infoboxer/navigation/sections.rb', line 116

def in_sections
  main_node = parent.is_a?(Tree::Document) ? self : lookup_parents[-2]
  
  heading = if main_node.is_a?(Tree::Heading)
    main_node.lookup_prev_siblings(Tree::Heading, level: main_node.level - 1).last
  else
    main_node.lookup_prev_siblings(Tree::Heading).last
  end
  return Tree::Nodes[] unless heading
  
  section = Section.new(heading,
    heading.next_siblings.
      take_while{|n| !n.is_a?(Tree::Heading) || n.level < heading.level}
  )
  Tree::Nodes[section, *heading.in_sections]
end