Skip to content

tuzz/ascii_tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ascii Tree

Build Status

Parses a usable tree from ASCII art.

Ascii Tree turns something humans understand into something computers understand. It is an expressive and efficient way to define trees.

## Usage

root = AsciiTree.parse('

      # Christmas themed tree:

              chestnuts
              /     |  \
          roasting  on  an
            /   \         \
        open   fire       jack
               /   \
            frost  nipping
                    /  |  \
                  on  your nose   # Ouch!

')

root.identity
#=> "chestnuts"

root.parent
#=> nil

root.children
#=> [#<AsciiTree::Node @identity="roasting">, ...]

Note: Backslash is an escape character in double quoted strings, so you'll need to use single quotes when parsing trees.

Multiple words

Use parenthesis to group words into a single node:

root = AsciiTree.parse('

          (     single node     )
              /    |    |    |   \
    (so is this)  but these are separate

')

root.identity
#=> "single node"

Values

You can set arbitrary values on nodes:

root = AsciiTree.parse('

        root{123}
         /    \
     a{"foo"}  b
       / \
      c   d{[1,2,3].reverse}

')

root.value
#=> 123

Note: Be careful to avoid spaces in blocks. AsciiTree doesn't support this.

Contribution

If you'd like to contribute, please open an issue or submit a pull request.

About

Parses a usable tree from ASCII art.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages