Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 94 lines (67 sloc) 3.388 kb
92175dcb »
2010-04-10 Read this.
1 # redwood
d177c9ce »
2010-04-07 Initial commit to redwood.
2
92175dcb »
2010-04-10 Read this.
3 Simple Ruby trees. Redwood is a simple implementation of a tree data structure in pure Ruby. It provides a few things:
d177c9ce »
2010-04-07 Initial commit to redwood.
4
92175dcb »
2010-04-10 Read this.
5 + The `redwood` command-line tool: like the Unix [`tree`](http://mama.indstate.edu/users/ice/tree/) tool, but in Ruby!
6 + The Redwood module for basic tree-esqueness.
7 + Redwood::Node class for basic tree-nodiness
8 + Redwood::FileNode class for representing Directories and Files in a tree-like way.
d177c9ce »
2010-04-07 Initial commit to redwood.
9
92175dcb »
2010-04-10 Read this.
10 [RDoc](http://rdoc.info/projects/mwunsch/redwood) | [Gem](http://rubygems.org/gems/redwood)
d177c9ce »
2010-04-07 Initial commit to redwood.
11
92175dcb »
2010-04-10 Read this.
12 ## Installation
13
14 gem install redwood
15
16 ## `redwood`
17
18 The `redwood` command-line tool attempts a pure Ruby implementation of [tree](http://man.cx/tree).
19
20 USAGE: redwood [ OPTIONS ] [ DIRECTORY ]
21
22 Looks a bit like this:
23
24 Redwood
25 |-- bin
26 | `-- redwood
27 |-- Gemfile
28 |-- lib
29 | |-- redwood
30 | | |-- filenode.rb
31 | | `-- node.rb
32 | `-- redwood.rb
33 |-- LICENSE
34 |-- pkg
35 | `-- redwood-0.0.1.gem
36 |-- Rakefile
37 |-- README.md
38 |-- redwood.gemspec
39 `-- test
40 |-- helper.rb
41 `-- test_redwood.rb
42
43 5 directories, 12 files
44
fd59a30f »
2010-04-10 Updating readme with link to manpage
45 Help is a `redwood --help` away. See also: [redwood(1)](http://mwunsch.github.com/redwood/)
92175dcb »
2010-04-10 Read this.
46
47 ## `Redwood`
48
49 The Redwood module is a module for including/extending tree-like features on your objects. It stores nodes in an Array. The only requirement for children is that they too include/extend tree-like features.
50
51 Methods include:
52
53 root? ## Is this a root node? Meaning, it has no parent.
54 leaf? ## Is this a leaf node? Meaning, is it without children?
55 root ## Get the root node in this tree.
56 children ## Get the children of this node.
57 siblings ## Get this nodes siblings.
58 only_child? ## Is this node without siblings?
59 has_children? ## Does this node have children?
60 ancestors ## All of the parent nodes of this node.
61 descendants ## All of the descendant nodes of this node.
62 depth ## Integer representing how deep this node is in the tree.
63 ## A root node has a depth of 1, its children: 2, etc.
8e76ca33 »
2010-04-13 New methods
64 height ## The length of this node to its furthest descendant.
65 ## A leaf node has a height of 1.
92175dcb »
2010-04-10 Read this.
66 unlink ## Detach this node from its parent.
67 prune ## Unlink all of this node's chidren.
8e76ca33 »
2010-04-13 New methods
68 graft ## Add a node to this node's children.
92175dcb »
2010-04-10 Read this.
69 walk ## Recursively yield every node in this tree to a block
70 view ## Make a fancy string representation of the tree
71 ## as seen in the command-line tool
72
73 ### Redwood::Node
74
75 The Redwood::Node class is a simple implementation of the Redwood module. It is a good starting point for other trees. It adds new methods:
76
77 add_child(name) ## Add a child node. Nodes can have a #name.
78 [](name) ## Lookup children node by their #name.
8e76ca33 »
2010-04-13 New methods
79 <<(node) ## Alias for `graft`.
92175dcb »
2010-04-10 Read this.
80
81 #### Redwood::FileNode
82
83 The Redwood::FileNode class is an example use-case for Redwood, and it powers the `redwood` CLI. It stores a directory tree in a Redwood-backed structure. It has one primary method that does the magic:
84
85 dir = Redwood::FileNode.scandir '~/Projects/Redwood'
86
87 That will go through the directory and build a Redwood tree. Redwood::FileNode objects have methods that correspond to the `File` class. So you can do things like `dir.directory?` or `dir.chmod`.
88
89 Now go forth and grow some Ruby-flavored trees.
90
91 ## Copyright
92
93 Redwood is Copyright (c) 2010 Mark Wunsch and is licensed under the [MIT License](http://creativecommons.org/licenses/MIT/).
Something went wrong with that request. Please try again.