diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 982a1e6..885690a 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -85,7 +85,7 @@ class Wrestler < ActiveRecord::Base def unfinished_matches all_matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number} end - + def result_by_bout(bout) bout_match = all_matches.select{|m| m.bout_number == bout and m.finished == 1} if bout_match.size == 0 @@ -99,6 +99,19 @@ class Wrestler < ActiveRecord::Base end end + def result_by_id(id) + bout_match = all_matches.select{|m| m.id == id and m.finished == 1} + if bout_match.size == 0 + return "" + end + if bout_match.first.winner_id == self.id + return "W #{bout_match.first.bracket_score_string}" + end + if bout_match.first.winner_id != self.id + return "L #{bout_match.first.bracket_score_string}" + end + end + def match_against(opponent) all_matches.select{|m| m.w1 == opponent.id or m.w2 == opponent.id} end @@ -119,6 +132,15 @@ class Wrestler < ActiveRecord::Base return round_match.bout_number end end + + def match_id_by_round(round) + round_match = all_matches.select{|m| m.round == round}.first + if round_match.blank? + return "BYE" + else + return round_match.id + end + end def all_matches return matches.select{|m| m.w1 == self.id or m.w2 == self.id} diff --git a/app/views/schools/stats.html.erb b/app/views/schools/stats.html.erb index 2bb20bc..9a45ded 100644 --- a/app/views/schools/stats.html.erb +++ b/app/views/schools/stats.html.erb @@ -40,7 +40,7 @@ - <%= wrestler.result_by_bout(m.bout_number) %> + <%= wrestler.result_by_id(m.id) %> <% end %> <% end %> diff --git a/app/views/tournaments/_pool.html.erb b/app/views/tournaments/_pool.html.erb index 68e1581..3a02e68 100644 --- a/app/views/tournaments/_pool.html.erb +++ b/app/views/tournaments/_pool.html.erb @@ -22,7 +22,7 @@ <% @round = 1 %> <% until @matches.select{|m| m.round == @round}.blank? %> <% if @round <= @pools %> - <%= w.bout_by_round(@round) %>
<%= w.result_by_bout(w.bout_by_round(@round)) %> + <%= w.bout_by_round(@round) %>
<%= w.result_by_id(w.match_id_by_round(@round)) %> <% end %> <% @round = @round + 1 %> <% end %> diff --git a/app/views/wrestlers/show.html.erb b/app/views/wrestlers/show.html.erb index 626d01e..1388035 100644 --- a/app/views/wrestlers/show.html.erb +++ b/app/views/wrestlers/show.html.erb @@ -85,7 +85,7 @@ <%= m.bout_number %> <%= m.bracket_position %> <%= m.list_w1_stats %>
<%= m.list_w2_stats %> - <%= @wrestler.result_by_bout(m.bout_number) %> + <%= @wrestler.result_by_id(m.id) %> <% end %>