0.0
No commit activity in last 3 years
No release in over 3 years
Help parse table-like output such as from raw SQL
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.8.0
>= 0.9.20
 Project Readme

Tableparser

A gem for parsing table-like formats like from SQL output such as MySQL (when it's not batch-formatted).

io = StringIO.new <<-EOS
+---------+---------+
| col1    | col2    |
+---------+---------+
| val     | val     |
| val     | val     |
+---------+---------+
EOS
Tableparser.parse(io)
# => [['col1', 'col2'], ['val', 'val'], ['val', 'val']]

It can also parse the content in to instances of a Struct class.

MyRow = Struct.new(:col1, :col2)
Tableparser.parse_to_struct(io, MyRow)
# => [#<struct MyRow col1="val", col2="val">, #<struct MyRow col1="val", col2="val">]

Also comes with a handy tableparser exectuable:

$ echo "SELECT 1 AS one, 2 AS two" | mysql --table
+-----+-----+
| one | two |
+-----+-----+
|   1 |   2 |
+-----+-----+

$ echo "SELECT 1 AS one, 2 AS two" | mysql --table | tableparser
one,two
1,2

Installation

Add this line to your application's Gemfile:

gem 'tableparser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tableparser

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/zachmargolis/tableparser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Tableparser project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.