Avoid trucate column at printing table


#1

Hi,

I’ve a table defined as the code below:

table = Table(%w[Page Position Domain URL Description])

And I fill it as you can see:

table << [iPage, iPosition, sDomain, sURL, sDescription]

When I finish I want output the table doing this:

myfile.puts table.to_s

but the content of the columns is too large and I get this:

±---------------------------------------------------------------------------->>
| Page | Position | Domain | >>
±---------------------------------------------------------------------------->>
| 1 | 1 | www.miltrabajos.com | http://www.miltrabajos.com/Ofe>>
| 1 | 2 | www.miltrabajos.com | http://www.miltrabajos.com/CAM>>

How can I avoid the trucate of the table?

Thanks in advance!


#2

As a guess - because you don’t actually say it yourself - this is a
question about the Ruport library, right?

I remember this being a bit of a pain to make do what I wanted.

(Digs through old code). Oh yes, in a custom Renderer you can do

options { |o| o.ignore_table_width = true }

However I’m not sure if it’s possible to this with the default renderer
for a table (i.e. Table#to_s as you’re doing above). Possibly you could
fake the method which works out the screen size to give a much larger
table width.

Ruport has its own google group - you’d probably be better off asking
there.

HTH,

Brian.


#3

Finally I’ve find the solution myself

I’m newbie with Ruby and Ruport. The solution is to call de “to_text”
method of the table instead of “to_s” and use the “:ignore_table_width”
attribute.

myfile.puts table.to_text( :ignore_table_width => true, :width => 200)

I read this option in the documentation, but I didn’t known how to use
it.

Now this works fine and produces this output:

±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Page | Position | Domain | URL | Description |
±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | 1 | barcelona.campusanuncios.com | http://barcelona.campusanuncios.com/detempleo-1892452216X-Oferta-de-Barcelona.html | Oferta de Empleo Primer empleo como programador Barcelona Espa🞠|
| 1 | 2 | empleo.trovit.es | http://empleo.trovit.es/ofertas-empleo/programador-php-barcelona | programador php barcelona - Trovit Empleo |