Parent

Class/Module Index [+]

Quicksearch

Webgen::ProxyNode

Encapsulates a node. This class is needed when a hierarchy of nodes should be created but the original hierarchy should not be destroyed.

Attributes

children[RW]

Array of child proxy nodes.

node[R]

The encapsulated node.

parent[RW]

The parent proxy node.

Public Class Methods

new(parent, node) click to toggle source

Create a new proxy node under parent (also has to be a ProxyNode object) for the real node node.

# File lib/webgen/node.rb, line 448
def initialize(parent, node)
  @parent = parent
  @node = node
  @children = []
end

Public Instance Methods

flatten!() click to toggle source

Turn the hierarchy of proxy nodes into a flat list.

# File lib/webgen/node.rb, line 477
def flatten!
  result = []
  while !self.children.empty?
    result << self.children.shift
    result.last.parent = self
    self.children.unshift(*result.last.children)
    result.last.children = []
  end
  self.children = result
end
sort!(value = true) click to toggle source

Sort recursively all children of the node using the wrapped nodes. If value is false, no sorting is done at all. If it is true, then the default sort mechanism is used (see Node#<=>). Otherwise value has to be a meta information key on which should be sorted.

# File lib/webgen/node.rb, line 457
def sort!(value = true)
  return self unless value

  if value.kind_of?(String)
    self.children.sort! do |a,b|
      aval, bval = a.node[value].to_s, b.node[value].to_s
      if aval !~ /\D/ && aval !~ /\D/
        aval = aval.to_i
        bval = bval.to_i
      end
      aval <=> bval
    end
  else
    self.children.sort! {|a,b| a.node <=> b.node}
  end
  self.children.each {|child| child.sort!(value)}
  self
end
to_list() click to toggle source

Return the hierarchy under this node as nested list of alcn values.

# File lib/webgen/node.rb, line 489
def to_list
  self.children.inject([]) {|temp, n| temp << n.node.alcn; temp += ((t = n.to_list).empty? ? [] : [t]) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.