1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-04 13:43:48 +00:00
Files
wrestlingdev.com/app/models/tournamentmatchgen.rb
RJ Osborne c041286943 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.
2015-05-26 19:26:15 -04:00

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