[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Back on the List - Two questions

list. rb

8/2/2008 6:12:00 PM

[Note: parts of this message were removed to make it a legal post.]

It's been a while but it feels good to be back.

I have a quick question for the group:

Given the following:

content = [
["something special a", "ok cool a", "tahsnk a"],
["something specccccccccial a", "ok cooooool a", "tahsnk a"]
]
content.each {|i|
puts i.join("\t")
}
#something special a ok cool a tahsnk a
#something specccccccccial a ok cooooool a tahsnk a

I would like to print this out as such:
something special a ok cool a tahsnk a
something specccccccccial a ok cooooool a tahsnk a

I remember seeing a module or example like this somewhere.. Any ideas? I was
thinking it was pretty print at first but after looking, I guess not?

5 Answers

Gregory Brown

8/2/2008 6:21:00 PM

0

On Sat, Aug 2, 2008 at 2:12 PM, list. rb <list.rb@gmail.com> wrote:
> It's been a while but it feels good to be back.
>
> I have a quick question for the group:
>
> Given the following:
>
> content = [
> ["something special a", "ok cool a", "tahsnk a"],
> ["something specccccccccial a", "ok cooooool a", "tahsnk a"]
> ]
> content.each {|i|
> puts i.join("\t")
> }
> #something special a ok cool a tahsnk a
> #something specccccccccial a ok cooooool a tahsnk a
>
> I would like to print this out as such:
> something special a ok cool a tahsnk a
> something specccccccccial a ok cooooool a tahsnk a
>
> I remember seeing a module or example like this somewhere.. Any ideas? I was
> thinking it was pretty print at first but after looking, I guess not?

Well, it's a bit like killing a mosquito with a bazooka, but you could
use Ruport for this:

>> require "rubygems"
=> true
>> require "ruport"
=> true
>> content = [
?> ["something special a", "ok coola", "tahsnk a"],
?> ["something speccccccccccccial a", "ok cooool a", "tahsnk a"]
>> ]
=> [["something special a", "ok coola", "tahsnk a"], ["something
speccccccccccccial a", "ok cooool a", "tahsnk a"]]
>> puts Table(:data => content)
+---------------------------------------------------------+
| something special a | ok coola | tahsnk a |
| something speccccccccccccial a | ok cooool a | tahsnk a |
+---------------------------------------------------------+

But if you don't want the decorations, you'd need to tweak things.
Feel free to take a look at the (not exactly pretty) source and re-use
whatever code you'd like:

http://github.com/ruport/ruport/tree/master/lib/ruport/formatt...


-greg

--
Killer Ruby PDF Generation named after a magnificent sea creature:
http://github.com/sa... | Non-tech stuff at:
http://metametta.bl...

list. rb

8/2/2008 8:23:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Nice.. that was exactly what I was looking for. Thanks!

On Sat, Aug 2, 2008 at 2:20 PM, Gregory Brown <gregory.t.brown@gmail.com>wrote:

> On Sat, Aug 2, 2008 at 2:12 PM, list. rb <list.rb@gmail.com> wrote:
> > It's been a while but it feels good to be back.
> >
> > I have a quick question for the group:
> >
> > Given the following:
> >
> > content = [
> > ["something special a", "ok cool a", "tahsnk a"],
> > ["something specccccccccial a", "ok cooooool a", "tahsnk a"]
> > ]
> > content.each {|i|
> > puts i.join("\t")
> > }
> > #something special a ok cool a tahsnk a
> > #something specccccccccial a ok cooooool a tahsnk a
> >
> > I would like to print this out as such:
> > something special a ok cool a tahsnk a
> > something specccccccccial a ok cooooool a tahsnk a
> >
> > I remember seeing a module or example like this somewhere.. Any ideas? I
> was
> > thinking it was pretty print at first but after looking, I guess not?
>
> Well, it's a bit like killing a mosquito with a bazooka, but you could
> use Ruport for this:
>
> >> require "rubygems"
> => true
> >> require "ruport"
> => true
> >> content = [
> ?> ["something special a", "ok coola", "tahsnk a"],
> ?> ["something speccccccccccccial a", "ok cooool a", "tahsnk a"]
> >> ]
> => [["something special a", "ok coola", "tahsnk a"], ["something
> speccccccccccccial a", "ok cooool a", "tahsnk a"]]
> >> puts Table(:data => content)
> +---------------------------------------------------------+
> | something special a | ok coola | tahsnk a |
> | something speccccccccccccial a | ok cooool a | tahsnk a |
> +---------------------------------------------------------+
>
> But if you don't want the decorations, you'd need to tweak things.
> Feel free to take a look at the (not exactly pretty) source and re-use
> whatever code you'd like:
>
> http://github.com/ruport/ruport/tree/master/lib/ruport/formatt...
>
>
> -greg
>
> --
> Killer Ruby PDF Generation named after a magnificent sea creature:
> http://github.com/sa... | Non-tech stuff at:
> http://metametta.bl...
>
>

Shadowfirebird

8/2/2008 9:00:00 PM

0

content.each do |i|
i.each{|j| printf "%30s ", j}
puts
end

Or is that too simplistic?

On Sat, Aug 2, 2008 at 9:23 PM, list. rb <list.rb@gmail.com> wrote:
> Nice.. that was exactly what I was looking for. Thanks!
>
> On Sat, Aug 2, 2008 at 2:20 PM, Gregory Brown <gregory.t.brown@gmail.com>wrote:
>
>> On Sat, Aug 2, 2008 at 2:12 PM, list. rb <list.rb@gmail.com> wrote:
>> > It's been a while but it feels good to be back.
>> >
>> > I have a quick question for the group:
>> >
>> > Given the following:
>> >
>> > content = [
>> > ["something special a", "ok cool a", "tahsnk a"],
>> > ["something specccccccccial a", "ok cooooool a", "tahsnk a"]
>> > ]
>> > content.each {|i|
>> > puts i.join("\t")
>> > }
>> > #something special a ok cool a tahsnk a
>> > #something specccccccccial a ok cooooool a tahsnk a
>> >
>> > I would like to print this out as such:
>> > something special a ok cool a tahsnk a
>> > something specccccccccial a ok cooooool a tahsnk a
>> >
>> > I remember seeing a module or example like this somewhere.. Any ideas? I
>> was
>> > thinking it was pretty print at first but after looking, I guess not?
>>
>> Well, it's a bit like killing a mosquito with a bazooka, but you could
>> use Ruport for this:
>>
>> >> require "rubygems"
>> => true
>> >> require "ruport"
>> => true
>> >> content = [
>> ?> ["something special a", "ok coola", "tahsnk a"],
>> ?> ["something speccccccccccccial a", "ok cooool a", "tahsnk a"]
>> >> ]
>> => [["something special a", "ok coola", "tahsnk a"], ["something
>> speccccccccccccial a", "ok cooool a", "tahsnk a"]]
>> >> puts Table(:data => content)
>> +---------------------------------------------------------+
>> | something special a | ok coola | tahsnk a |
>> | something speccccccccccccial a | ok cooool a | tahsnk a |
>> +---------------------------------------------------------+
>>
>> But if you don't want the decorations, you'd need to tweak things.
>> Feel free to take a look at the (not exactly pretty) source and re-use
>> whatever code you'd like:
>>
>> http://github.com/ruport/ruport/tree/master/lib/ruport/formatt...
>>
>>
>> -greg
>>
>> --
>> Killer Ruby PDF Generation named after a magnificent sea creature:
>> http://github.com/sa... | Non-tech stuff at:
>> http://metametta.bl...
>>
>>
>



--
Me, I imagine places that I have never seen / The colored lights in
fountains, blue and green / And I imagine places that I will never go
/ Behind these clouds that hang here dark and low
But it's there when I'm holding you / There when I'm sleeping too /
There when there's nothing left of me / Hanging out behind the
burned-out factories / Out of reach but leading me / Into the
beautiful sea

Gregory Brown

8/2/2008 9:50:00 PM

0

On Sat, Aug 2, 2008 at 4:59 PM, Shadowfirebird <shadowfirebird@gmail.com> wrote:
> content.each do |i|
> i.each{|j| printf "%30s ", j}
> puts
> end

If you combine this with a function that first figures out an
appropriate column width based on the size of the strings in that
column, this simple approach would be much more lightweight than what
we do in Ruport, for sure (but not quite as full featured).

But usually, dynamically determining column width is a must-have
unless you can make a lot of assumptions about the data you're
displaying. For example, showing telephone numbers with fixed width
hard coded columns would be fine, but email addresses, probably not so
clear cut.

-greg

--
Killer Ruby PDF Generation named after a magnificent sea creature:
http://github.com/sa... | Non-tech stuff at:
http://metametta.bl...

Marc Heiler

8/2/2008 10:03:00 PM

0

Cool, didn't know this example with ruport :-)
--
Posted via http://www.ruby-....