mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-05-13 01:07:03 +00:00
rough cut of getting rid of the matches collection being passed around
Associated Weight and Match-- the FK already existed in the domain Reduced argument counts on assignLoserNames and assignBouts; trying to pass a Tournament around more This was a tough nut to crack. Looking back, I tried to eat too much of the horse at once on this refactor.
This commit is contained in:
@@ -2,52 +2,36 @@ class Tournamentmatchgen
|
||||
|
||||
def initialize(tournament)
|
||||
@tournament = tournament
|
||||
@matches = @tournament.matches
|
||||
end
|
||||
|
||||
def genMatches
|
||||
if @tournament.tournament_type == "Pool to bracket"
|
||||
@matches = poolToBracket()
|
||||
poolToBracket()
|
||||
end
|
||||
@matches
|
||||
@tournament.matches
|
||||
end
|
||||
|
||||
def poolToBracket
|
||||
destroyMatches
|
||||
buildTournamentWeights
|
||||
generateMatches
|
||||
saveMatches
|
||||
@matches
|
||||
end
|
||||
|
||||
def destroyMatches
|
||||
@tournament.destroyAllMatches
|
||||
@matches = []
|
||||
end
|
||||
|
||||
def buildTournamentWeights
|
||||
@tournament.weights.sort_by{|x|[x.max]}.each do |weight|
|
||||
matches = Pool.new(weight).generatePools()
|
||||
last_match = matches.sort_by{|m| m.round}.last
|
||||
@tournament.weights.order(:max).each do |weight|
|
||||
Pool.new(weight).generatePools()
|
||||
last_match = @tournament.matches.where(weight: weight).order(round: :desc).limit(1).first
|
||||
highest_round = last_match.round
|
||||
Poolbracket.new(weight, highest_round).generateBracketMatches()
|
||||
end
|
||||
@tournament.save!
|
||||
@matches = @tournament.matches
|
||||
end
|
||||
|
||||
def generateMatches
|
||||
@matches =
|
||||
Losernamegen.new.assignLoserNames(
|
||||
Boutgen.new.assignBouts(@matches, @tournament.weights),
|
||||
@tournament.weights)
|
||||
Boutgen.new.assignBouts(@tournament)
|
||||
Losernamegen.new.assignLoserNames(@tournament)
|
||||
end
|
||||
|
||||
def saveMatches
|
||||
@tournament.save!
|
||||
@matches.each do |m|
|
||||
m.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user