Class: WhiteCloth::DataStructures::StandardNode

Inherits:
Tree::TreeNode
  • Object
show all
Defined in:
lib/data_structures/standard_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(node_id, content) ⇒ StandardNode

Constructors



29
30
31
# File 'lib/data_structures/standard_node.rb', line 29

def initialize(node_id, content)
  super(node_id, content)
end

Instance Method Details

#<<(child_node) ⇒ Object

Add a new child node to the current node.



38
39
40
# File 'lib/data_structures/standard_node.rb', line 38

def << (child_node)
  self.add(child_node)
end

#[](block_name) ⇒ Object

Look for the designated block within tree starting at the current node. If the block_name is nil or ROOT, than we return the root of the current tree (i.e. ourselves).



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/data_structures/standard_node.rb', line 44

def [] (block_name)
  
  # We need to work out which node has the right content. Since
  # the nodes are effectively unordered, we have to look (potentially)
  # at every node
  unless block_name.nil? or block_name == "ROOT"
    self.each{|child|
      if child.content === block_name then
        return child
      end
    }
    return nil
  else
    return self
  end      
end