tj / terminal-table

Ruby ASCII Table Generator, simple and feature rich.
MIT License
1.53k stars 121 forks source link

is there a way to display rows from a SQL talble? #102

Open kulldox opened 6 years ago

kulldox commented 6 years ago

I'm trying to use terminal-table to display rows from SQL tables (for ex using "pg" gem), where you'll have multiple columns, and don't need a heading on the row.


| col1 | col2 | col3 | coln... |
| val1 | val2 | val3 | valn... |
| val1 | val2 | val3 | valn... |
| val1 | val2 | val3 | valn... |

The result is a hash, so I can do result.keys and then feed it to terminal-table like :headings => row.keys. But for rows :rows => row.values will fail with NoMethodError: undefined method `each' for "4196505504":String.

So, basically, it would need a switch to turn off the expectation of the row to be pairs of keys and values, and just print the whole row array in a line.

nanobowers commented 3 years ago

Not sure I understand the question (and probably two years too late), but can you split the values with #.each_slice(num) ?