From aec47ddf1316336628b9eb33d693249763f751c9 Mon Sep 17 00:00:00 2001 From: RJ Osborne Date: Sat, 23 May 2015 06:15:44 -0400 Subject: [PATCH] introduced a constructor for Pool and reduced arguments on roundRobin and generatePools --- app/models/pool.rb | 18 +++++++++++------- app/models/tournamentmatchgen.rb | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/models/pool.rb b/app/models/pool.rb index 6bf15f4..168f59b 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -1,18 +1,22 @@ class Pool - def generatePools(weight, tournament) - matches = [] - @pools = weight.pools + def initialize(weight) + @weight = weight @pool = 1 - while @pool <= @pools - matches += roundRobin(weight.wrestlers, weight, tournament) + end + + def generatePools + matches = [] + pools = @weight.pools + while @pool <= pools + matches += roundRobin(@weight) @pool += 1 end return matches end - def roundRobin(wrestlers,weight,tournament) + def roundRobin(weight) matches = [] - @wrestlers = wrestlers.select{|w| w.generatePoolNumber == @pool}.to_a + @wrestlers = weight.wrestlers.select{|w| w.generatePoolNumber == @pool}.to_a @poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse @poolMatches.each_with_index do |b, index| round = index + 1 diff --git a/app/models/tournamentmatchgen.rb b/app/models/tournamentmatchgen.rb index c418e32..a88f36a 100644 --- a/app/models/tournamentmatchgen.rb +++ b/app/models/tournamentmatchgen.rb @@ -27,7 +27,7 @@ class Tournamentmatchgen def buildTournamentWeights @tournament.weights.sort_by{|x|[x.max]}.each do |weight| - matches = Pool.new.generatePools(weight, @tournament.id) + matches = Pool.new(weight).generatePools() weight_matches = matches.select{|m| m.weight_id == weight.id } last_match = weight_matches.sort_by{|m| m.round}.last highest_round = last_match.round