From 2a57cafd6db1b9b0e39700a836cc9e02f0ae1f17 Mon Sep 17 00:00:00 2001 From: RJ Osborne Date: Sat, 23 May 2015 08:07:11 -0400 Subject: [PATCH] extracted wrestlers_for_pool method removed unnecessary select --- app/models/pool.rb | 2 +- app/models/tournament.rb | 4 ++-- app/models/tournamentmatchgen.rb | 3 +-- app/models/weight.rb | 4 ++++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/pool.rb b/app/models/pool.rb index 37c928d..cb823c8 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -16,7 +16,7 @@ class Pool def roundRobin matches = [] - wrestlers = @weight.wrestlers.select{|w| w.generatePoolNumber == @pool}.to_a + wrestlers = @weight.wrestlers_for_pool(@pool) poolMatches = RoundRobinTournament.schedule(wrestlers).reverse poolMatches.each_with_index do |b, index| round = index + 1 diff --git a/app/models/tournament.rb b/app/models/tournament.rb index c3e094d..b41c740 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -28,10 +28,10 @@ class Tournament < ActiveRecord::Base def upcomingMatches if matches.nil? - return matches + return nil else generateMatchups - return matches + matches end end diff --git a/app/models/tournamentmatchgen.rb b/app/models/tournamentmatchgen.rb index a88f36a..5285559 100644 --- a/app/models/tournamentmatchgen.rb +++ b/app/models/tournamentmatchgen.rb @@ -28,8 +28,7 @@ class Tournamentmatchgen def buildTournamentWeights @tournament.weights.sort_by{|x|[x.max]}.each do |weight| 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 + last_match = matches.sort_by{|m| m.round}.last highest_round = last_match.round @matches += Poolbracket.new.generateBracketMatches(matches, weight, highest_round) end diff --git a/app/models/weight.rb b/app/models/weight.rb index 0298e8b..3ae2cf8 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -8,6 +8,10 @@ class Weight < ActiveRecord::Base self.tournament.destroyAllMatches end + def wrestlers_for_pool(pool) + wrestlers.select{|w| w.generatePoolNumber == pool}.to_a + end + def pools @wrestlers = self.wrestlers if @wrestlers.size <= 6