Class: Tree::TreeNode
- Defined in
 - lib/kyanite/tree.rb
 
Rubytree Additions
- Kyanite definitions
 - Kyanite tests and examples
 - Base class
 - Usage
 - 
require 'kyanite/tree'
 
Additions for rubytree (collapse)
- 
  
    
      - (Array) all_child_keys 
    
    
  
  
    
Returns an array of all child keys.
 - 
  
    
      - (Object) find(node_name) 
    
    
  
  
    
As opposed to [] the entire tree is searched.
 - 
  
    
      - print_tree(level = 0, breite = 8) 
    
    
  
  
    
now it works.
 - 
  
    
      - (String) to_s 
    
    
  
  
    
now handles symbols in the tree as well.
 
Instance Method Details
- (Array) all_child_keys
Returns an array of all child keys. The whole tree is searched.
      83 84 85 86 87 88 89 90 91  | 
    
      # File 'lib/kyanite/tree.rb', line 83 def all_child_keys result = @children_hash.keys || [] children do |c| #puts "durchsuche #{c}" next if c.children_hash.empty? result += c.all_child_keys end result end  | 
  
- (Object) find(node_name)
As opposed to [] the entire tree is searched. Returns the first hit.
      64 65 66 67 68 69 70 71 72 73 74 75  | 
    
      # File 'lib/kyanite/tree.rb', line 64 def find( node_name ) return self if self.name == node_name result = self[node_name] return result if result children do |c| next if c.children.empty? #puts "durchsuche #{c.name}" result = c.find(node_name) return result if result end nil end  | 
  
- print_tree(level = 0, breite = 8)
This method returns an undefined value.
now it works
      39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59  | 
    
      # File 'lib/kyanite/tree.rb', line 39 def print_tree(level = 0, breite = 8) if is_root? print "*" elsif level == 0 print 'X' else print "|" unless parent.is_last_sibling? print(" " * (level - 1 ) * breite) print(is_last_sibling? ? "+" : "|") print "---" print(has_children? ? "+" : ">") end puts " #{name}" children { |child| child.print_tree(level + 1)} nil end  | 
  
- (String) to_s
now handles symbols in the tree as well
      27 28 29 30 31 32 33 34  | 
    
      # File 'lib/kyanite/tree.rb', line 27 def to_s ":#{@name}" # "Node Name: #{@name}" + # " Content: #{@content || '<Empty>'}" + # " Parent: #{(isRoot?() ? '<None>' : @parent.name)}" + # " Children: #{@children.length}" + # " Total Nodes: #{size()}" end  |