Termtable
Installation
Add this line to your application's Gemfile:
gem 'termtable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install termtable
Usage
A table instance can take a 2 dimensional array for the rows.
table = Termtable::Table.new [[1, 2, 3], [4, 5, 6]]
This can also be given as a hash with a rows key.
table = Termtable::Table.new rows: [[1, 2, 3], [4, 5, 6]]
puts table.render
+--+--+--+
|1 |2 |3 |
|4 |5 |6 |
+--+--+--+
Headers
Headers can be given as the first array
Termtable::Table.new ['Header A', 'Header B'], [['a1', 'a2'], ['b1', 'b2']]
Also as a headers key
Termtable::Table.new headers: ['Header A', 'Header B'], rows: [['a1', 'a2'], ['b1', 'b2']]
+---------+---------+
|Header A |Header B |
+---------+---------+
|a1 |a2 |
|b1 |b2 |
+---------+---------+
Padding
It is possible to pass a padding argument to the render method
table = Termtable::Table.new rows: [['a1', 'a2'], ['b1', 12345]]
puts table.render(padding: 3)
+-----+--------+
|a1 |a2 |
|b1 |12345 |
+-----+--------+
Alignment
It is possible to pass an alignment argument to render
table = Termtable::Table.new rows: [['a1', 'a2'], ['b1', 123456]]
puts table.render(alignment: 'center')
+----+--------+
| a1 | a2 |
| b1 | 123456 |
+----+--------+
Development
To run the tests
$ rake
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/nikkypx/termtable.