From 9976fd5869cbb1c48518b6f4f850c21809dfc6fa Mon Sep 17 00:00:00 2001 From: jcwimer Date: Sat, 28 Mar 2015 18:16:32 +0000 Subject: [PATCH] Added before save on wrestler and weight. Also fixed fourPoolNumbers for weight --- app/models/weight.rb | 28 ++++++++++++++++++++++++++++ app/models/wrestler.rb | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/models/weight.rb b/app/models/weight.rb index 6915734..54864a8 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -4,6 +4,11 @@ class Weight < ActiveRecord::Base attr_accessor :pools, :bracket_size, :bracket_type, :poolRounds, :totalRounds + before_save do + self.tournament.matchups_array = nil + self.tournament.save + end + def pools @wrestlers = self.wrestlers if @wrestlers.size <= 6 @@ -57,6 +62,29 @@ class Weight < ActiveRecord::Base end return wrestlers end + + def fourPoolNumbers(wrestlers) + pool = 1 + wrestlers.sort_by{|x|[x.original_seed]}.reverse.each do |w| + if w.original_seed == 1 + w.poolNumber = 1 + elsif w.original_seed == 2 + w.poolNumber = 2 + elsif w.original_seed == 3 + w.poolNumber = 3 + elsif w.original_seed == 4 + w.poolNumber = 4 + else + w.poolNumber = pool + end + if pool < 4 + pool = pool + 1 + else + pool =1 + end + end + return wrestlers + end def bracket_size @wrestlers = Wrestler.where(weight_id: self.id) diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index 15a88c2..ef0d353 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -2,8 +2,14 @@ class Wrestler < ActiveRecord::Base belongs_to :school belongs_to :weight has_one :tournament, through: :weight - attr_accessor :allMatches, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage + attr_accessor :allMatches, :isWrestlingThisRound, :boutByRound, :seasonWinPercentage, :poolNumber + before_save do + self.tournament.matchups_array = nil + self.tournament.save + end + + def isWrestlingThisRound(matchRound) @gMatches = Match.where(g_id: self.id, round: matchRound) @rMatches = Match.where(r_id: self.id, round: matchRound)