Project

ascii_tree

0.0
No commit activity in last 3 years
No release in over 3 years
Parses a usable tree from ASCII art.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.4
~> 3.0
~> 0.31
 Project Readme

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.