# Urgent Output Layout

**URL:** <https://www.ruby-forum.com/t/urgent-output-layout/157382>\
**Category:** Rails\
**Created:** [January 10, 2009, 10:56am UTC](https://www.ruby-forum.com/t/urgent-output-layout/157382 "2009-01-10T10:56:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakenewuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@rakenewuser](https://www.ruby-forum.com/u/rakenewuser)\
**Post date:** [January 10, 2009, 10:56am UTC](https://www.ruby-forum.com/t/urgent-output-layout/157382/1 "2009-01-10T10:56:34Z")

</div>

Hi,

Anyone can help me on how to layout my output? See my source code;

# Start Here

report = Hash.new

PTable.all(:conditions =\> [‘status = “success” AND created\_at \>= ? AND  
created\_at \< ?’, Date.today.midnight, Date.today.midnight +  
1.day]).inject(0) { |total, p\_table|  
unless translations.flatten.any? {|t| t == p\_table.id || t ==  
pt.rd\_field}

evalsum = eval(p\_table.rd\_field) if !p\_table.rd\_field.nil?  
norm = evalsum[:ctms].inject(0) {|sum, room| sum + norm.length}  
nopn = evalsum[:ctms].length

```
if report[evalsum[:hname]].nil?
   report.store(evalsum[:hname], {'norm' => norm, 'nopn' => nopn})
else
   report[evalsum[:hname]]['norm'] += norm
   report[evalsum[:hname]]['nopn'] += nopn
end

```

end  
}  
puts report.inspect  
}  
end

# End Here

Here are the Output of my code;

{“AAA”=\>{“nopn”=\>2, “norm”=\>4}, “BBB”=\>{“nopn”=\>1, “norm”=\>2},  
“CCC”=\>{“nopn”=\>1, “norm”=\>2}, “DDD”=\>{“nopn”=\>1, “norm”=\>2},  
“EEE”=\>{“nopn”=\>5, “norm”=\>10}, “FFF”=\>{“nopn”=\>1, “norm”=\>2},  
“GGG”=\>{“nopn”=\>4, “norm”=\>8}, “HHH”=\>{“nopn”=\>1, “norm”=\>2},  
“III”=\>{“nopn”=\>1, “norm”=\>2}, “JJJ”=\>{“nopn”=\>1, “norm”=\>2},  
“KKK”=\>{“nopn”=\>1, “norm”=\>2}, “LLL”=\>{“nopn”=\>1, “norm”=\>2},  
“MMM”=\>{“nopn”=\>2, “norm”=\>4}}

How can I do these Output Layout I need like belows;

AAA 2 4  
BBB 1 2  
CCC 1 2  
DDD 1 2  
EEE 5 10  
FFF 1 2  
GGG 4 8  
HHH 1 2  
III 1 2  
JJJ 1 2  
KKK 1 2  
LLL 1 2  
MMM 2 4

Thanks in Advance!

---

<div class="post-metadata">

**Author:** ![rakenewuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@rakenewuser](https://www.ruby-forum.com/u/rakenewuser)\
**Post date:** [January 11, 2009, 7:18am UTC](https://www.ruby-forum.com/t/urgent-output-layout/157382/2 "2009-01-11T07:18:36Z")

</div>

Vishwanath Nayak wrote:

> Hi,
> 
> replace puts report.inspect with the following
> 
> report.keys.sort.each do |key|  
> puts “#{key} #{report[key][“nopn”]} #{report[key][“norm”]}”  
> end
> 
> NAYAK
> 
> On Sat, Jan 10, 2009 at 3:26 PM, Ferdie Ferdie \<  
> removed\_email\_address@domain.invalid\> wrote:
> 
> > 1.day]).inject(0) { |total, p\_table|  
> > report[evalsum[:hname]][‘norm’] += norm  
> > Here are the Output of my code;  
> > How can I do these Output Layout I need like belows;  
> > JJJ 1 2
> > 
> > >
> 
> –
> 
> - NAYAK

Hi Nayak,

Fantastic, it works! thank you for the immediate reply.

Cheer’s  
/Ferdie

---

<div class="post-metadata">

**Author:** ![rakenewuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@rakenewuser](https://www.ruby-forum.com/u/rakenewuser)\
**Post date:** [January 10, 2009, 1:48pm UTC](https://www.ruby-forum.com/t/urgent-output-layout/157382/3 "2009-01-10T13:48:32Z")

</div>

Hi,

replace puts report.inspect with the following

report.keys.sort.each do |key|  
puts “#{key} #{report[key][“nopn”]} #{report[key][“norm”]}”  
end

NAYAK

On Sat, Jan 10, 2009 at 3:26 PM, Ferdie Ferdie \<  
removed\_email\_address@domain.invalid\> wrote:

> 1.day]).inject(0) { |total, p\_table|  
> report[evalsum[:hname]][‘norm’] += norm  
> Here are the Output of my code;  
> How can I do these Output Layout I need like belows;  
> JJJ 1 2
> 
> >

–

- NAYAK
