Forum: Ruby Avoid trucate column at printing table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
09cb2a62131c4d40542fb4663f896955?d=identicon&s=25 Marc Pou (marcp)
on 2008-11-30 00:28
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!
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2008-11-30 17:51
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.
09cb2a62131c4d40542fb4663f896955?d=identicon&s=25 Marc Pou (marcp)
on 2008-12-01 10:45
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-1892... 
| Oferta de Empleo Primer empleo como  programador Barcelona Espa🞠   |
|    1 |        2 | empleo.trovit.es              | 
http://empleo.trovit.es/ofertas-empleo/programador... 
| programador php barcelona - Trovit Empleo                             |
This topic is locked and can not be replied to.