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