1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00
Files
wrestlingdev.com/app/models/poolbracket.rb
RJ Osborne c855da0e6e Ripped state out of Poolbracket
Implicitly added tournament_id to matches generated by Poolbracket
Removed explicit tournament assignment at save
2015-05-26 19:26:15 -04:00

77 lines
3.7 KiB
Ruby

class Poolbracket
def generateBracketMatches(matches, weight, highest_round)
if weight.pool_bracket_type == "twoPoolsToSemi"
return twoPoolsToSemi(matches, weight, highest_round)
elsif weight.pool_bracket_type == "twoPoolsToFinal"
return twoPoolsToFinal(matches, weight, highest_round)
elsif weight.pool_bracket_type == "fourPoolsToQuarter"
return fourPoolsToQuarter(matches, weight, highest_round)
elsif weight.pool_bracket_type == "fourPoolsToSemi"
return fourPoolsToSemi(matches, weight, highest_round)
end
return matches
end
def twoPoolsToSemi(matches, weight, round)
round += 1
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Runner Up Pool 2", "Semis", 1)
matches = createMatchup(matches, weight, round, "Winner Pool 2", "Runner Up Pool 1", "Semis", 2)
round += 1
matches = matches.select{|m| m.weight_id == weight.id}
matches = createMatchup(matches, weight, round,"","","1/2",1)
matches = createMatchup(matches, weight, round,"","","3/4",1)
end
def twoPoolsToFinal(matches,weight,round)
round += 1
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Winner Pool 2", "1/2", 1)
matches = createMatchup(matches, weight, round, "Runner Up Pool 1", "Runner Up Pool 2", "3/4", 1)
end
def fourPoolsToQuarter(matches,weight,round)
round += 1
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Runner Up Pool 2", "Quarter", 1)
matches = createMatchup(matches, weight, round, "Winner Pool 4", "Runner Up Pool 3", "Quarter", 2)
matches = createMatchup(matches, weight, round, "Winner Pool 2", "Runner Up Pool 1", "Quarter", 3)
matches = createMatchup(matches, weight, round, "Winner Pool 3", "Runner Up Pool 4", "Quarter", 4)
round += 1
matches = createMatchup(matches, weight, round, "", "", "Semis", 1)
matches = createMatchup(matches, weight, round, "", "", "Semis", 2)
matches = createMatchup(matches, weight, round, "", "", "Conso Semis", 1)
matches = createMatchup(matches, weight, round, "", "", "Conso Semis", 2)
round += 1
matches = createMatchup(matches, weight, round, "", "", "1/2", 1)
matches = createMatchup(matches, weight, round, "", "", "3/4", 1)
matches = createMatchup(matches, weight, round, "", "", "5/6", 1)
matches = createMatchup(matches, weight, round, "", "", "7/8", 1)
end
def fourPoolsToSemi(matches,weight,round)
round += 1
matches = createMatchup(matches, weight, round, "Winner Pool 1", "Winner Pool 4", "Semis", 1)
matches = createMatchup(matches, weight, round, "Winner Pool 2", "Winner Pool 3", "Semis", 2)
matches = createMatchup(matches, weight, round, "Runner Up Pool 1", "Runner Up Pool 4", "Conso Semis", 1)
matches = createMatchup(matches, weight, round, "Runner Up Pool 2", "Runner Up Pool 3", "Conso Semis", 2)
round += 1
matches = createMatchup(matches, weight, round, "", "", "1/2", 1)
matches = createMatchup(matches, weight, round, "", "", "3/4", 1)
matches = createMatchup(matches, weight, round, "", "", "5/6", 1)
matches = createMatchup(matches, weight, round, "", "", "7/8", 1)
end
def createMatchup(matches, weight, round, w1_name, w2_name, bracket_position, bracket_position_number)
tournament = weight.tournament
match = tournament.matches.create(
loser1_name: w1_name,
loser2_name: w2_name,
weight_id: weight.id,
round: round,
bracket_position: bracket_position,
bracket_position_number: bracket_position_number
)
matches << match
end
end