mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-04 13:43:48 +00:00
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.
38 lines
845 B
Ruby
38 lines
845 B
Ruby
class Tournamentmatchgen
|
|
|
|
def initialize(tournament)
|
|
@tournament = tournament
|
|
end
|
|
|
|
def genMatches
|
|
if @tournament.tournament_type == "Pool to bracket"
|
|
poolToBracket()
|
|
end
|
|
@tournament.matches
|
|
end
|
|
|
|
def poolToBracket
|
|
destroyMatches
|
|
buildTournamentWeights
|
|
generateMatches
|
|
end
|
|
|
|
def destroyMatches
|
|
@tournament.destroyAllMatches
|
|
end
|
|
|
|
def buildTournamentWeights
|
|
@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
|
|
end
|
|
|
|
def generateMatches
|
|
Boutgen.new.assignBouts(@tournament)
|
|
Losernamegen.new.assignLoserNames(@tournament)
|
|
end
|
|
end
|