# Data output

**URL:** <https://www.ruby-forum.com/t/data-output/152712>\
**Category:** Ruby\
**Created:** [November 6, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/data-output/152712 "2008-11-06T18:25:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [November 6, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/data-output/152712/1 "2008-11-06T18:25:33Z")

</div>

I am processing data from an array which basically involves me searching  
for specific information and outputting the results that match eg.

…  
if data == 100  
puts “#{data.time\_written}”

I have just inserted a step which adds some additional criteria. This  
states if you find data that equals 100 does it happens more than 10  
times in one day.

This all works fine. What i want is some kind of nested if statement  
thats does the following:

if data == 100  
if data happens more than 5 times in one day  
print out the results of all the data that equals 100 but highlight  
(colour code, italics etc)the data within the results that happens more  
than 5 times in a day.

An example of the results might be

100 monday - - - BOLD  
100 monday - - - BOLD  
100 monday - - - BOLD  
100 monday - - - BOLD  
100 monday - - - BOLD  
100 monday - - - BOLD  
100 tuesday - - - NORMAL

Hope this makes sense.

Regards

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [November 6, 2008, 7:58pm UTC](https://www.ruby-forum.com/t/data-output/152712/2 "2008-11-06T19:58:51Z")

</div>

-------- Original-Nachricht --------

> Datum: Fri, 7 Nov 2008 02:23:40 +0900  
> Von: Stuart C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Data output

> ## Regards
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Dear Stuart,

you can output your report as a html document using textile:

[http://whytheluckystiff.net/ruby/redcloth/](http://whytheluckystiff.net/ruby/redcloth/)

using very simple markup styles.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [November 7, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/data-output/152712/3 "2008-11-07T14:10:01Z")

</div>

On Thu, Nov 6, 2008 at 6:23 PM, Stuart C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 100 monday - - - BOLD  
> 100 monday - - - BOLD  
> 100 monday - - - BOLD  
> 100 monday - - - BOLD  
> 100 monday - - - BOLD  
> 100 monday - - - BOLD  
> 100 tuesday - - - NORMAL

This is how I’d do it: first build an histogram of the data. In this  
case  
you want to count how many there are of a combination of data and day.  
Then print the array checking against the histogram for choosing style:

irb(main):001:0\> TimeData = Struct.new :data, :day  
=\> TimeData  
irb(main):002:0\> a = []  
=\> []  
irb(main):003:0\> 6.times {a \<\< TimeData.new(100, “monday”)}  
=\> 6  
irb(main):004:0\> a \<\< TimeData.new(100, “tuesday”)  
=\> [#, #, #,  
#, #, #, #]  
irb(main):005:0\> h = Hash.new(0)  
=\> {}  
irb(main):007:0\> a.inject(h) {|histo,time| h[[time.data, time.day]] +=  
1}  
=\> 1  
irb(main):008:0\> h  
=\> {[100, “tuesday”]=\>1, [100, “monday”]=\>6}  
irb(main):009:0\> a.each do |time|  
irb(main):010:1\* if h[[time.data, time.day]] \> 5  
irb(main):011:2\> puts “#{time.data} #{time.day}”  
irb(main):012:2\> else  
irb(main):013:2\* puts “#{time.data} #{time.day}”  
irb(main):014:2\> end  
irb(main):015:1\> end  
100 monday  
100 monday  
100 monday  
100 monday  
100 monday  
100 monday  
100 tuesday

Hope this helps.

Jesus.
