To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / gems / rubytree-0.5.2 / README @ 442:753f1380d6bc

History | View | Annotate | Download (4.66 KB)

1

    
2
   __       _           _
3
   /__\_   _| |__  _   _| |_ _ __ ___  ___
4
  / \// | | | '_ \| | | | __| '__/ _ \/ _ \
5
 / _  \ |_| | |_) | |_| | |_| | |  __/  __/
6
 \/ \_/\__,_|_.__/ \__, |\__|_|  \___|\___|
7
                  |___/
8

    
9
  (c) 2006, 2007 Anupam Sengupta
10
  http://rubytree.rubyforge.org
11

    
12
Rubytree is a simple implementation of the generic Tree data structure.  This
13
implementation is node-centric, where the individual nodes on the tree are the
14
primary objects and drive the structure.
15

    
16
== INSTALL:
17

    
18
Rubytree is an open source project and is hosted at:
19

    
20
   http://rubytree.rubyforge.org
21

    
22
Rubytree can be downloaded as a Rubygem or as a tar/zip file from:
23

    
24
   http://rubyforge.org/frs/?group_id=1215&release_id=8817
25

    
26
The file-name is one of:
27

    
28
    rubytree-<VERSION>.gem - The Rubygem
29
    rubytree-<VERSION>.tgz - GZipped source files
30
    rubytree-<VERSION>.zip - Zipped  source files
31

    
32
Download the appropriate file-type for your system.
33

    
34
It is recommended to install Rubytree as a Ruby Gem, as this is an easy way to
35
keep the version updated, and keep multiple versions of the library available on
36
your system.
37

    
38
=== Installing the Gem
39

    
40
To Install the Gem, from a Terminal/CLI command prompt, issue the command:
41

    
42
   gem install rubytree
43

    
44
This should install the gem file for Rubytree. Note that you may need to be a
45
super-user (root) to successfully install the gem.
46

    
47
=== Installing from the tgz/zip file
48

    
49
Extract the archive file (tgz or zip) and run the following command from the
50
top-level source directory:
51

    
52
    ruby ./setup.rb
53

    
54
You may need administrator/super-user privileges to complete the setup using
55
this method.
56

    
57
== DOCUMENTATION:
58

    
59
The primary class for this implementation is Tree::TreeNode. See the
60
class documentation for an usage example.
61

    
62
From a command line/terminal prompt, you can issue the following command to view
63
the text mode ri documentation:
64

    
65
    ri Tree::TreeNode
66

    
67
Documentation on the web is available at:
68

    
69
http://rubytree.rubyforge.org/rdoc
70

    
71
== EXAMPLE:
72

    
73
The following code-snippet implements this tree structure:
74

    
75
                 +------------+
76
                 |    ROOT    |
77
                 +-----+------+
78
         +-------------+------------+
79
         |                          |
80
 +-------+-------+          +-------+-------+
81
 |  CHILD 1      |          |  CHILD 2      |
82
 +-------+-------+          +---------------+
83
         |
84
         |
85
 +-------+-------+
86
 | GRANDCHILD 1  |
87
 +---------------+
88

    
89
 require 'tree'
90

    
91
 myTreeRoot = Tree::TreeNode.new("ROOT", "Root Content")
92

    
93
 myTreeRoot << Tree::TreeNode.new("CHILD1", "Child1 Content") << Tree::TreeNode.new("GRANDCHILD1", "GrandChild1 Content")
94

    
95
 myTreeRoot << Tree::TreeNode.new("CHILD2", "Child2 Content")
96

    
97
 myTreeRoot.printTree
98

    
99
 child1 = myTreeRoot["CHILD1"]
100

    
101
 grandChild1 = myTreeRoot["CHILD1"]["GRANDCHILD1"]
102

    
103
 siblingsOfChild1Array = child1.siblings
104

    
105
 immediateChildrenArray = myTreeRoot.children
106

    
107
 # Process all nodes
108

    
109
 myTreeRoot.each { |node| node.content.reverse }
110

    
111
 myTreeRoot.remove!(child1) # Remove the child
112

    
113
== LICENSE:
114

    
115
Rubytree is licensed under BSD license.
116

    
117
Copyright (c) 2006, 2007 Anupam Sengupta
118

    
119
All rights reserved.
120

    
121
Redistribution and use in source and binary forms, with or without modification,
122
are permitted provided that the following conditions are met:
123

    
124
- Redistributions of source code must retain the above copyright notice, this
125
  list of conditions and the following disclaimer.
126

    
127
- Redistributions in binary form must reproduce the above copyright notice, this
128
  list of conditions and the following disclaimer in the documentation and/or
129
  other materials provided with the distribution.
130

    
131
- Neither the name of the organization nor the names of its contributors may
132
  be used to endorse or promote products derived from this software without
133
  specific prior written permission.
134

    
135
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
136
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
137
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
138
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
139
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
140
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
141
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
142
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
144
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145

    
146

    
147
(Document Revision: $Revision: 1.16 $ by $Author: anupamsg $)