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 448 def initialize(parent, node) @parent = parent @node = node @children = [] end
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 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
Generated with the Darkfish Rdoc Generator 2.