mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-18 21:42:16 +00:00
introduced constructor on TournamentMatchGen
This commit is contained in:
@@ -36,7 +36,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generateMatchups
|
def generateMatchups
|
||||||
@matches = Tournamentmatchgen.new.genMatches(self)
|
@matches = Tournamentmatchgen.new(self).genMatches()
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroyAllMatches
|
def destroyAllMatches
|
||||||
@@ -44,6 +44,3 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,45 @@
|
|||||||
class Tournamentmatchgen
|
class Tournamentmatchgen
|
||||||
def genMatches(tournament)
|
|
||||||
if tournament.tournament_type == "Pool to bracket"
|
def initialize(tournament)
|
||||||
@matches = poolToBracket(tournament)
|
@tournament = tournament
|
||||||
|
@matches = @tournament.matches
|
||||||
|
end
|
||||||
|
|
||||||
|
def genMatches
|
||||||
|
if @tournament.tournament_type == "Pool to bracket"
|
||||||
|
@matches = poolToBracket()
|
||||||
end
|
end
|
||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|
||||||
def poolToBracket(tournament)
|
def poolToBracket
|
||||||
tournament.destroyAllMatches
|
destroyMatches()
|
||||||
|
@tournament.weights.sort_by{|x|[x.max]}.each do |w|
|
||||||
|
buildTournamentWeights(w)
|
||||||
|
end
|
||||||
|
@matches = Boutgen.new.assignBouts(@matches,@tournament.weights)
|
||||||
|
@matches = Losernamegen.new.assignLoserNames(@matches,@tournament.weights)
|
||||||
|
saveMatches
|
||||||
|
return @matches
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroyMatches
|
||||||
|
@tournament.destroyAllMatches
|
||||||
@matches = []
|
@matches = []
|
||||||
tournament.weights.sort_by{|x|[x.max]}.each do |w|
|
|
||||||
buildTournamentWeights(tournament.id, w)
|
|
||||||
end
|
|
||||||
@matches = Boutgen.new.assignBouts(@matches,tournament.weights)
|
|
||||||
@matches = Losernamegen.new.assignLoserNames(@matches,tournament.weights)
|
|
||||||
saveMatches(tournament,@matches)
|
|
||||||
return @matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def buildTournamentWeights(tournament_id, weight)
|
def buildTournamentWeights(weight)
|
||||||
@wrestlers = weight.wrestlers
|
@wrestlers = weight.wrestlers
|
||||||
@matches = Pool.new.generatePools(weight, tournament_id, @matches)
|
@matches = Pool.new.generatePools(weight, @tournament.id, @matches)
|
||||||
@weight_matches = @matches.select{|m| m.weight_id == weight.id }
|
@weight_matches = @matches.select{|m| m.weight_id == weight.id }
|
||||||
@last_match = @weight_matches.sort_by{|m| m.round}.last
|
@last_match = @weight_matches.sort_by{|m| m.round}.last
|
||||||
@highest_round = @last_match.round
|
@highest_round = @last_match.round
|
||||||
@matches = Poolbracket.new.generateBracketMatches(@matches, weight, @highest_round)
|
@matches = Poolbracket.new.generateBracketMatches(@matches, weight, @highest_round)
|
||||||
end
|
end
|
||||||
|
|
||||||
def saveMatches(tournament,matches)
|
def saveMatches
|
||||||
matches.each do |m|
|
@matches.each do |m|
|
||||||
m.tournament_id = tournament.id
|
m.tournament_id = @tournament.id
|
||||||
m.save
|
m.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user