1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Use match id instead of bout number when looking stuff up on bracket view.

This commit is contained in:
2021-12-22 13:13:44 +00:00
parent 6db1dacbb6
commit f0e8c99b9f
4 changed files with 26 additions and 4 deletions

View File

@@ -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}

View File

@@ -40,7 +40,7 @@
</tbody>
</table>
</td>
<td><%= wrestler.result_by_bout(m.bout_number) %>
<td><%= wrestler.result_by_id(m.id) %>
</tr>
<% end %>
<% end %>

View File

@@ -22,7 +22,7 @@
<% @round = 1 %>
<% until @matches.select{|m| m.round == @round}.blank? %>
<% if @round <= @pools %>
<td><%= w.bout_by_round(@round) %><br><%= w.result_by_bout(w.bout_by_round(@round)) %></td>
<td><%= w.bout_by_round(@round) %><br><%= w.result_by_id(w.match_id_by_round(@round)) %></td>
<% end %>
<% @round = @round + 1 %>
<% end %>

View File

@@ -85,7 +85,7 @@
<td><%= m.bout_number %></td>
<td><%= m.bracket_position %></td>
<td><%= m.list_w1_stats %><br><%= m.list_w2_stats %></td>
<td><%= @wrestler.result_by_bout(m.bout_number) %>
<td><%= @wrestler.result_by_id(m.id) %>
</tr>
<% end %>
</tbody>