class HTOTConv::Outline::Tree
Attributes
item[RW]
parent[R]
Public Class Methods
new(item=nil, parent=nil)
click to toggle source
# File lib/htot_conv/outline.rb, line 98 def initialize(item=nil, parent=nil) @item = item @parent = parent @children = [] end
Public Instance Methods
add(item)
click to toggle source
# File lib/htot_conv/outline.rb, line 114 def add(item) child = Tree.new(item, self) @children << child self end
Also aliased as: <<
ancestors()
click to toggle source
# File lib/htot_conv/outline.rb, line 154 def ancestors Enumerator.new do |y| node = self.parent until (node.nil? || node.root?) y << node node = node.parent end end end
descendants()
click to toggle source
# File lib/htot_conv/outline.rb, line 164 def descendants Enumerator.new do |y| @children.each do |child| y << child child.descendants.each do |descendant| y << descendant end end end end
each() { |child| ... }
click to toggle source
# File lib/htot_conv/outline.rb, line 121 def each # :yield: child @children.each do |v| yield v if block_given? end @children.dup end
leaf?()
click to toggle source
# File lib/htot_conv/outline.rb, line 110 def leaf? @children.empty? end
next()
click to toggle source
# File lib/htot_conv/outline.rb, line 134 def next if root? nil else brothers = parent.to_a index = brothers.index(self) (index + 1 < brothers.length)? brothers[index + 1] : nil end end
prev()
click to toggle source
# File lib/htot_conv/outline.rb, line 144 def prev if root? nil else brothers = parent.to_a index = brothers.index(self) (index - 1 >= 0)? brothers[index - 1] : nil end end
root()
click to toggle source
# File lib/htot_conv/outline.rb, line 128 def root node = self node = node.parent until node.root? node end
root?()
click to toggle source
# File lib/htot_conv/outline.rb, line 106 def root? @parent.nil? end