Prev | Current Page 92 | Next

David Berube

"Practical Reporting with Ruby and Rails"

(In
this particular case, you are formatting the entire row, so you could use the format_row
method.)
Next, you loop through all of the games, tally the players??™ wins and losses for each
game, and write them to the spreadsheet:
Game.find(:all).each do |game|
win_count = Play.count(:conditions=>[
"player_id = ? AND
game_id= ? AND
won=true",
player.id,
game.id])
loss_count = Play.count(:conditions=>[
"player_id = ? AND
game_id= ? AND
won=false",
player.id,
game.id])
worksheet.write(current_row, 0, [game.name, win_count, loss_count])
current_row=current_row+1
end
CHAPTER 4 n CREATING REPORTS ON THE DESKTOP 59
The two calls to the Active Record count method (discussed in Chapter 2) count the
wins and losses, respectively. You then use the worksheet object??™s write method to put
the information into the spreadsheet, and continue on to the next game. After all of the
games have been reported, you continue on to the next player. After all of the players
have been reported, you close the workbook, and you??™re finished:
workbook.


Pages:
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
długopisy reklamowe Porównywarka ubezpieczenie na narty zasłony Golec uOrkiestra 3