Parent

Included Modules

Class/Module Index [+]

Quicksearch

Webgen::Tree

Represents a tree of nodes.

Attributes

dummy_root[R]

The dummy root. This is the default node that gets created when the Tree is created sothat the real root node can be treated like any other node. It has only one child, namely the real root node of the tree.

node_access[R]

Direct access to the hashes for node resolving. Only use this for reading purposes! If you just want to get a specific node for an alcn/acn/output path, use node instead.

node_info[R]

The hash containing processing information for each node. This is normally not accessed directly but via the Node#node_info method.

Public Class Methods

new() click to toggle source

Create a new Tree object.

# File lib/webgen/tree.rb, line 26
def initialize
  @node_access = {:alcn => {}, :acn => {}, :path => {}}
  @node_info = {}
  @dummy_root = Node.new(self, '', '')
end

Public Instance Methods

[](path, type = :alcn) click to toggle source
Alias for: node
delete_node(node_or_alcn) click to toggle source

Delete the node identified by node_or_alcn and all of its children from the tree.

The message :before_node_deleted is sent with the to-be-deleted node before this node is actually deleted from the tree.

# File lib/webgen/tree.rb, line 72
def delete_node(node_or_alcn)
  n = node_or_alcn.kind_of?(Node) ? node_or_alcn : @node_access[:alcn][node_or_alcn]
  return if n.nil? || n == @dummy_root

  n.children.dup.each {|child| delete_node(child)}

  website.blackboard.dispatch_msg(:before_node_deleted, n)
  n.parent.children.delete(n)
  @node_access[:alcn].delete(n.alcn)
  @node_access[:acn][n.acn].delete(n)
  @node_access[:path].delete(n.path)

  node_info.delete(n.alcn)
end
node(path, type = :alcn) click to toggle source

Access a node via a path of a specific type. If type is alcn then path has to be an absolute localized canonical name, if type is acn then path has to be an absolute canonical name and if type is path then path needs to be an output path.

Returns the requested Node or nil if such a node does not exist.

# File lib/webgen/tree.rb, line 42
def node(path, type = :alcn)
  (type == :acn ? @node_access[type][path] && @node_access[type][path].first : @node_access[type][path])
end
Also aliased as: []
register_node(node) click to toggle source

A utility method called by Node#initialize. This method should not be used directly!

# File lib/webgen/tree.rb, line 48
def register_node(node)
  if @node_access[:alcn].has_key?(node.alcn)
    raise "Can't have two nodes with same absolute lcn: #{node}"
  else
    @node_access[:alcn][node.alcn] = node
  end
  (@node_access[:acn][node.acn] ||= []) << node
  register_path(node)
end
register_path(node) click to toggle source

A utility method called by Node#reinit. This method should not be used directly!

# File lib/webgen/tree.rb, line 59
def register_path(node)
  return if node['no_output']
  if @node_access[:path].has_key?(node.path)
    raise "Can't have two nodes with same output path: #{node.path}"
  else
    @node_access[:path][node.path] = node
  end
end
root() click to toggle source

The real root node of the tree.

# File lib/webgen/tree.rb, line 33
def root
  @dummy_root.children.first
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.