Parent

Class 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.

parent[RW]

The parent proxy node.

node[R]

The encapsulated 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 449
449:     def initialize(parent, node)
450:       @parent = parent
451:       @node = node
452:       @children = []
453:     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 478
478:     def flatten!
479:       result = []
480:       while !self.children.empty?
481:         result << self.children.shift
482:         result.last.parent = self
483:         self.children.unshift(*result.last.children)
484:         result.last.children = []
485:       end
486:       self.children = result
487:     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 458
458:     def sort!(value = true)
459:       return self unless value
460: 
461:       if value.kind_of?(String)
462:         self.children.sort! do |a,b|
463:           aval, bval = a.node[value].to_s, b.node[value].to_s
464:           if aval !~ /\D/ && aval !~ /\D/
465:             aval = aval.to_i
466:             bval = bval.to_i
467:           end
468:           aval <=> bval
469:         end
470:       else
471:         self.children.sort! {|a,b| a.node <=> b.node}
472:       end
473:       self.children.each {|child| child.sort!(value)}
474:       self
475:     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 490
490:     def to_list
491:       self.children.inject([]) {|temp, n| temp << n.node.alcn; temp += ((t = n.to_list).empty? ? [] : [t]) }
492:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.