Project

rowx

0.0
Low commit activity in last 3 years
No release in over a year
Generates XML from rows of labelled text, nested text, and plain text
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.9, >= 0.9.3
 Project Readme

Introducing the RowX gem

require 'rowx'

txt =<<EOF
title: testing 123

-----------------------------
path: 1
type: date only
desc:

input:
  date: 22-Apr-2011 12:34
  entry: * * * * *

output:
  date: 2011-04-22 12:34

------------------------------

path: 2
type: date only
desc:

input:
  date: 22-Apr-2011 12:34
  entry: * * * * *

output:
  date: 2011-04-22 12:34

------------------------------

EOF

Output:

irb(main):214:0> puts xml
<?xml version='1.0' encoding='UTF-8'?>
<root>
  <summary>
    <title>testing 123</title>
  </summary>
  <item>
    <path>1</path>
    <type>date only</type>
    <desc/>
    <input>
      <item>
        <date>22-Apr-2011 12:34</date>
        <entry>* * * * *</entry>
      </item>
    </input>
    <output>
      <item>
        <date>2011-04-22 12:34</date>
      </item>
    </output>
  </item>
  <item>
    <path>2</path>
    <type>date only</type>
    <desc/>
    <input>
      <item>
        <date>22-Apr-2011 12:34</date>
        <entry>* * * * *</entry>
      </item>
    </input>
    <output>
      <item>
        <date>2011-04-22 12:34</date>
      </item>
    </output>
  </item>
</root>

The RowX gem makes it more convenient to generate XML with minimal syntax. In the above code a heredoc contains a couple of records which is then passed to the RowX Object to be converted to XML.

Notes:

  • Hash-type labels define the element names.
  • Indenting the line of text by 2 spaces will make the row a child element to the row above.
  • Blank lines and separator lines (-------) are disregarded.
  • A row is defined by the first label which is found to be repeated further down the text, or just the first label if there is only 1 row.
  • A summary element is created at the top of the XML for any text preceding the rows.
  • If a line of text contains no label it is automatically given the label 'description'.
  • The named keyword level can be used to define how many levels the tree should be parsed. The lowest level is 0.

Resources:

gem parse rowx ruby text