Project

line-tree

0.01
Low commit activity in last 3 years
No release in over a year
Line-tree parses indented lines of text and returns an array representing a tree structure.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.5, >= 1.5.14
 Project Readme

#Introducing the line-tree gem

The line-tree gem is designed to parse lines of text, with each line being parsed as separate text fields which can be represented as an array.

If the line is indented then it's treated as a nested array of the line above.

require 'line-tree'

lines =<<LINES
a
  b 123
  bike 456
LINES


LineTree.new(lines).to_a
#=> [["a", ["b 123"], ["bike 456"]]]

XML

puts LineTree.new(lines).to_xml

output:

<?xml version='1.0' encoding='UTF-8'?>
<a><b>123</b><bike>456</bike></a>

If you want the XML to use attributes, write the attributes as a hash after the element name e.g.

bike {colour: 'red'} 456