Class: OrgMode::NodeUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/org_mode/node_utils.rb

Class Method Summary collapse

Class Method Details

.convert_sequential_nodelist_into_tree(nodes) ⇒ Object

Public: transforms a sequental list of nodes into a tree structure setting parents and children on the nodes



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/org_mode/node_utils.rb', line 6

def self.convert_sequential_nodelist_into_tree(nodes)
  parent_stack = []
  nodes.map! do |node| 
    node.parent = parent_stack[node.stars - 1]
    if node.parent
      node.parent.children << node
    end
    parent_stack[node.stars] = node
  end

  # filter out all non root nodes
  nodes.select(&:root_node?)
end