1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 04:35:26 +00:00
Files
wrestlingdev.com/app/models/tournamentmatchgen.rb
RJ Osborne 9b2c2dde60 Converted class tournamentmatchgen into the GeneratesLoserNames module.
Here is another way to handle functionality that you may not want bloating your ActiveRecord class, yet belongs _on_ the model.
In this case, I feel there is an abstraction we are still sorely missing.
2015-05-27 23:29:51 -04:00

38 lines
814 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
@tournament.assignBouts
@tournament.assignLoserNames
end
end