Project

spacetree

0.0
No commit activity in last 3 years
No release in over 3 years
Generate a tree structure from a text file indented by spaces.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.6
 Project Readme

spacetree

A Ruby library to generate a tree structure from a text file indented by spaces.

Example

Given a text file tree.txt

foo
  bar
  baz

Parsing it:

require 'spacetree'
parser = Spacetree::Parser.new
tree = parser.parse File.read('tree.txt')
# tree is root node
tree.value # => nil
tree.children.map(&:value) # => ["foo"]
tree.children.map(&:children).flatten.map(&:value) # => ["bar", "baz"]

Emitting a tree as indented text:

puts tree.emit

or simple

puts tree

Author

Jan Friedrich janfri26@gmail.com

License

MIT license see file LICENSE.