Encapsulates a node. This class is needed when a hierarchy of nodes should be created but the original hierarchy should not be destroyed.
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
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 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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.