Is there a Ruby library that can put an array of arrays in an ascii table?

I am looking for a Ruby library that will specify an array of arrays (e.g. CSV) and output a string that displays the data in an ASCII table as follows:

+----------+-------------+ | route_id | route_color | +----------+-------------+ | 01-1079 | FFFF7C | | 04-1079 | FFFF7C | +----------+-------------+ 

Is there such a thing?

+7
source share
2 answers

https://github.com/visionmedia/terminal-table (Gem at http://rubygems.org/gems/terminal-table )

This library seems to be doing exactly what you want.

+10
source

https://github.com/tj/terminal-table is great for handling ASCII in the console.

You can try the following:

 require 'terminal-table/import' puts table(['route_id', 'route_color'], ["01-1079", "FFFF7C"], ["04-1079" , "FFFF7C"]) 

And the result should be:

 +----------+-------------+ | route_id | route_color | +----------+-------------+ | 01-1079 | FFFF7C | | 04-1079 | FFFF7C | +----------+-------------+ 
0
source

All Articles