C0 code coverage information
Generated on Thu Jun 07 11:33:59 -0400 2007 with rcov 0.8.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 class Game < ActiveRecord::Base
2 has_many :team_results, :dependent => :destroy
3 has_many :player_results, :dependent => :destroy
4 has_and_belongs_to_many :teams
5 belongs_to :room
6 belongs_to :round
7 belongs_to :tournament
8 validates_associated :team_results, :player_results
9
10 def self.completed
11 find(:all).select{|g| g.completed}
12 end
13
14 def self.incomplete
15 find(:all).reject{|g| g.completed}
16 end
17
18 def completed
19 !team_results.blank?
20 end
21
22 def winner
23 tied? ? nil : team_results.detect{|t| t.win}.team
24 end
25
26 def loser
27 tied? ? nil : team_results.detect{|t| t.lose}.team
28 end
29
30 def tied?
31 team_results[0].tie and team_results[1].tie
32 end
33
34 def player_results_for(teamm)
35 player_results.select{|play_res| play_res.player.team == teamm}
36 end
37
38 def process_round_results(params)
39 update_attribute(:tuh, params[:tuh])
40 process_team_results(params[:teams])
41 update_winner(self.team_results[0], self.team_results[1])
42 save!
43 end
44
45 def update_tiebreak(winner)
46 update_winner(team_results[0], team_results[1], winner)
47 end
48
49 private
50 def process_team_results(teams)
51 teams.each do |team_id,team_result|
52 players = team_result[:players]
53 team_result.reject! {|k,v| k == :players}
54 team = Team.find(team_id)
55 tr = self.team_results.create(team_result.merge({:game => self,
56 :tuh => self.tuh,:tournament => self.tournament}))
57 tr.team = team
58 tr.save!
59 prs = process_player_results(players)
60 prs.each do |p|
61 tr.powers += p.powers
62 tr.tossups += p.tossups
63 tr.negs += p.negs
64 end
65 tr.save!
66 end
67 end
68
69 def process_player_results(players)
70 prs = []
71 players.each do |player_id, player_result|
72 player = Player.find(player_id)
73 pr = self.player_results.create(player_result.merge({:game => self,
74 :tournament => self.tournament, :player => player}))
75 prs << pr
76 end
77 prs
78 end
79 def update_winner(team_A, team_B, winner = nil)
80 if winner
81 winning_team = self.tournament.teams.find winner
82 case winning_team
83 when team_A.team
84 team_A.update_attributes(:win => true, :tie => false)
85 team_B.update_attributes(:win => false, :tie => false)
86 when team_B.team
87 team_A.update_attributes(:win => false, :tie => false)
88 team_B.update_attributes(:win => true, :tie => false)
89 end
90 elsif team_A.score == team_B.score and !winner
91 team_A.win = false
92 team_A.tie = true
93 team_B.win = false
94 team_B.tie = true
95 elsif team_A.score > team_B.score
96 team_A.win = true
97 team_B.tie = false
98 team_B.win = false
99 team_B.tie = false
100 else
101 team_A.win = false
102 team_B.tie = false
103 team_B.win = true
104 team_B.tie = false
105 end
106 team_A.save
107 team_B.save
108 end
109
110 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.