Chris@0: Chris@0: __ _ _ Chris@0: /__\_ _| |__ _ _| |_ _ __ ___ ___ Chris@0: / \// | | | '_ \| | | | __| '__/ _ \/ _ \ Chris@0: / _ \ |_| | |_) | |_| | |_| | | __/ __/ Chris@0: \/ \_/\__,_|_.__/ \__, |\__|_| \___|\___| Chris@0: |___/ Chris@0: Chris@0: (c) 2006, 2007 Anupam Sengupta Chris@0: http://rubytree.rubyforge.org Chris@0: Chris@0: Rubytree is a simple implementation of the generic Tree data structure. This Chris@0: implementation is node-centric, where the individual nodes on the tree are the Chris@0: primary objects and drive the structure. Chris@0: Chris@0: == INSTALL: Chris@0: Chris@0: Rubytree is an open source project and is hosted at: Chris@0: Chris@0: http://rubytree.rubyforge.org Chris@0: Chris@0: Rubytree can be downloaded as a Rubygem or as a tar/zip file from: Chris@0: Chris@0: http://rubyforge.org/frs/?group_id=1215&release_id=8817 Chris@0: Chris@0: The file-name is one of: Chris@0: Chris@0: rubytree-.gem - The Rubygem Chris@0: rubytree-.tgz - GZipped source files Chris@0: rubytree-.zip - Zipped source files Chris@0: Chris@0: Download the appropriate file-type for your system. Chris@0: Chris@0: It is recommended to install Rubytree as a Ruby Gem, as this is an easy way to Chris@0: keep the version updated, and keep multiple versions of the library available on Chris@0: your system. Chris@0: Chris@0: === Installing the Gem Chris@0: Chris@0: To Install the Gem, from a Terminal/CLI command prompt, issue the command: Chris@0: Chris@0: gem install rubytree Chris@0: Chris@0: This should install the gem file for Rubytree. Note that you may need to be a Chris@0: super-user (root) to successfully install the gem. Chris@0: Chris@0: === Installing from the tgz/zip file Chris@0: Chris@0: Extract the archive file (tgz or zip) and run the following command from the Chris@0: top-level source directory: Chris@0: Chris@0: ruby ./setup.rb Chris@0: Chris@0: You may need administrator/super-user privileges to complete the setup using Chris@0: this method. Chris@0: Chris@0: == DOCUMENTATION: Chris@0: Chris@0: The primary class for this implementation is Tree::TreeNode. See the Chris@0: class documentation for an usage example. Chris@0: Chris@0: From a command line/terminal prompt, you can issue the following command to view Chris@0: the text mode ri documentation: Chris@0: Chris@0: ri Tree::TreeNode Chris@0: Chris@0: Documentation on the web is available at: Chris@0: Chris@0: http://rubytree.rubyforge.org/rdoc Chris@0: Chris@0: == EXAMPLE: Chris@0: Chris@0: The following code-snippet implements this tree structure: Chris@0: Chris@0: +------------+ Chris@0: | ROOT | Chris@0: +-----+------+ Chris@0: +-------------+------------+ Chris@0: | | Chris@0: +-------+-------+ +-------+-------+ Chris@0: | CHILD 1 | | CHILD 2 | Chris@0: +-------+-------+ +---------------+ Chris@0: | Chris@0: | Chris@0: +-------+-------+ Chris@0: | GRANDCHILD 1 | Chris@0: +---------------+ Chris@0: Chris@0: require 'tree' Chris@0: Chris@0: myTreeRoot = Tree::TreeNode.new("ROOT", "Root Content") Chris@0: Chris@0: myTreeRoot << Tree::TreeNode.new("CHILD1", "Child1 Content") << Tree::TreeNode.new("GRANDCHILD1", "GrandChild1 Content") Chris@0: Chris@0: myTreeRoot << Tree::TreeNode.new("CHILD2", "Child2 Content") Chris@0: Chris@0: myTreeRoot.printTree Chris@0: Chris@0: child1 = myTreeRoot["CHILD1"] Chris@0: Chris@0: grandChild1 = myTreeRoot["CHILD1"]["GRANDCHILD1"] Chris@0: Chris@0: siblingsOfChild1Array = child1.siblings Chris@0: Chris@0: immediateChildrenArray = myTreeRoot.children Chris@0: Chris@0: # Process all nodes Chris@0: Chris@0: myTreeRoot.each { |node| node.content.reverse } Chris@0: Chris@0: myTreeRoot.remove!(child1) # Remove the child Chris@0: Chris@0: == LICENSE: Chris@0: Chris@0: Rubytree is licensed under BSD license. Chris@0: Chris@0: Copyright (c) 2006, 2007 Anupam Sengupta Chris@0: Chris@0: All rights reserved. Chris@0: Chris@0: Redistribution and use in source and binary forms, with or without modification, Chris@0: are permitted provided that the following conditions are met: Chris@0: Chris@0: - Redistributions of source code must retain the above copyright notice, this Chris@0: list of conditions and the following disclaimer. Chris@0: Chris@0: - Redistributions in binary form must reproduce the above copyright notice, this Chris@0: list of conditions and the following disclaimer in the documentation and/or Chris@0: other materials provided with the distribution. Chris@0: Chris@0: - Neither the name of the organization nor the names of its contributors may Chris@0: be used to endorse or promote products derived from this software without Chris@0: specific prior written permission. Chris@0: Chris@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" Chris@0: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE Chris@0: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE Chris@0: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR Chris@0: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES Chris@0: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; Chris@0: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON Chris@0: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT Chris@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@0: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@0: Chris@0: Chris@0: (Document Revision: $Revision: 1.16 $ by $Author: anupamsg $)