mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-02 04:35:26 +00:00
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.
38 lines
814 B
Ruby
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
|