Multiple values in a single cell

7 views
Skip to first unread message

fatcat

unread,
Apr 13, 2010, 12:48:55 PM4/13/10
to Ruby Reports
1 #!/usr/bin/ruby
2
3 require 'rubygems'
4 require 'ruport'
5
6 table = Table(%w[Name Title Spouse Children])
7 table << { "Name" => "John",
8 "Title" => "Accountant",
9 "Spouse" => "Suzy",
10 "Children" => "John\ Jr."
11 }
12
13 table << { "Name" => "George",
14 "Title" => "Watchman",
15 "Spouse" => "Joan",
16 "Children" => %w[Georgette Georgina]
17 }
18
19 puts table


Which outputs:

+--------------------------------------------------+
| Name | Title | Spouse | Children |
+--------------------------------------------------+
| John | Accountant | Suzy | John Jr. |
| George | Watchman | Joan | GeorgetteGeorgina |
+--------------------------------------------------+


But what I'd like is:

+--------------------------------------------------+
| Name | Title | Spouse | Children |
+--------------------------------------------------+
| John | Accountant | Suzy | John Jr. |
| George | Watchman | Joan | Georgette |
| | Georgina |
+--------------------------------------------------+


Or something similar. Any way to do this? I've started looking at
customizing the Text renderer, but I am wondering if perhaps there is
an easier way that I've just overlooked. I've not used Ruports until
a few days ago. What a great bit of work here, I got rid of all my
ugly reporting hacks!

Andrew France

unread,
Apr 14, 2010, 3:01:15 AM4/14/10
to ruby-r...@googlegroups.com

I'm afraid as far as I can tell the text formatter code will only output
one row per row in the data table. You could probably iterate over each
row in the data table and create a new row with blank values whenever
you encounter an array value, but that's nasty and still wouldn't be the
exact output you're after. I think joining the array values with a
newline would break the table.

So yes I think you're right that the best way would be to override the
row builder in the text formatter!

Regards,
Andrew

fatcat

unread,
Apr 14, 2010, 9:37:38 AM4/14/10
to Ruby Reports

Yes I tried appending a "\n" and it does indeed break the table. OK,
I will look at the row builder...this is probably going to be a fair
amount of work, judging from a cursory look. Perhaps I can think of
something clever :-|

Thanks for responding! Cheers!

Andrew France

unread,
Apr 14, 2010, 10:22:42 AM4/14/10
to ruby-r...@googlegroups.com
fatcat,

Yeah it's a hard problem that's native to displaying it as text, it
wouldn't be so much of an issue in HTML or PDF. Getting the column
positioning correct based on the current text formatter will be very
difficult so I would hesitate in recommending even subclassing it.

You know, commas are good. :P

One last crazy thought, you could generate the table as HTML then use an
HTML to text converter!

Regards,
Andrew

Daniel L. McNulty

unread,
Apr 14, 2010, 1:52:04 PM4/14/10
to ruby-r...@googlegroups.com
Hmmm, that is an idea.

I've spent the morning on this problem but don't have an elegant solution.  I'll sleep on it and try again tomorrow.

-- Daniel L. McNulty
  404-939-2225


--
You received this message because you are subscribed to the Google Groups "Ruby Reports" group.
To post to this group, send email to ruby-r...@googlegroups.com.
To unsubscribe from this group, send email to ruby-reports...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-reports?hl=en.


Reply all
Reply to author
Forward
0 new messages