# Copyright (c) 2010-2011 David Love # # Permission to use, copy, modify, and/or distribute this software for # any purpose with or without fee is hereby granted, provided that the # above copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # @author David Love module WhiteCloth::DataStructures # Load the base tree data structure require "tree" class StandardNode < Tree::TreeNode ### ### Constructors ### def initialize(node_id, content) super(node_id, content) end ### ### Operators ### # Add a new child node to the current node. def << (child_node) self.add(child_node) end # Look for the designated block within tree starting at the current node. If the +block_name+ # is +nil+ or +ROOT+, than we return the root of the current tree (i.e. ourselves). def [] (block_name) # We need to work out which node has the right content. Since # the nodes are effectively unordered, we have to look (potentially) # at every node unless block_name.nil? or block_name == "ROOT" self.each{|child| if child.content === block_name then return child end } return nil else return self end end ### ### Accessors ### # State that +id+ is an alias for the node name. alias :id :name end end