1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-06 22:44:14 +00:00

Add boutNumber to upcomgingMatches

This commit is contained in:
2015-03-12 15:18:06 -04:00
parent dc9639cf1c
commit e8dd332bbc
4 changed files with 24 additions and 15 deletions

View File

@@ -1,15 +1,8 @@
class Bout class Bout
def assignBouts(tournament_id)
@round = 1
until matchesByRound(@round, tournament_id).blank? do
@matches = matchesByRound(@round, tournament_id)
giveBout(@matches)
@round += 1
end
end
def matchesByRound(round, tournament_id) def matchesByRound(round, matches)
@matches = Match.where(tournament_id: tournament_id, round: round) @matches = matches.select {|m| m.round == round}
return @matches return @matches
end end
@@ -18,7 +11,21 @@ class Bout
@matches.each_with_index do |m, i| @matches.each_with_index do |m, i|
bout = m.round * 1000 + i bout = m.round * 1000 + i
m.boutNumber = bout m.boutNumber = bout
m.save
end end
return @matches
end end
def assignBouts(matches)
@round = 1
until matchesByRound(@round, matches).blank? do
@matches = matchesByRound(@round, matches)
giveBout(@matches)
@round += 1
end
return matches
end
end end

View File

@@ -1,5 +1,5 @@
class Matchup class Matchup
attr_accessor :w1, :w2, :round, :weight_id attr_accessor :w1, :w2, :round, :weight_id, :boutNumber
# def w1 # def w1
# end # end

View File

@@ -17,6 +17,7 @@ class Tournament < ActiveRecord::Base
self.weights.sort_by{|x|[x.max]}.each do |weight| self.weights.sort_by{|x|[x.max]}.each do |weight|
@upcomingMatches = weight.generateMatchups(@matches) @upcomingMatches = weight.generateMatchups(@matches)
end end
@upcomingMatches = assignBouts(@upcomingMatches)
return @upcomingMatches return @upcomingMatches
end end
@@ -40,9 +41,10 @@ class Tournament < ActiveRecord::Base
def assignBouts def assignBouts(matches)
@bouts = Bout.new @bouts = Bout.new
@bouts.assignBouts(self.id) @matches = @bouts.assignBouts(matches)
return @matches
end end
end end

View File

@@ -18,7 +18,7 @@
<% @matches.each.map do |m| %> <% @matches.each.map do |m| %>
<tr> <tr>
<td>Round <%= m.round %></td> <td>Round <%= m.round %></td>
<td></td> <td><%= m.boutNumber %></td>
<td><%= m.weight_max %> lbs</td> <td><%= m.weight_max %> lbs</td>
<td><%= m.w_name(m.w1) %> vs. <%= m.w_name(m.w2) %></td> <td><%= m.w_name(m.w1) %> vs. <%= m.w_name(m.w2) %></td>
</tr> </tr>