mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-04 13:43:48 +00:00
Working on Pool class
This commit is contained in:
31
app/models/pool.rb
Normal file
31
app/models/pool.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class Pool
|
||||
def onePool(wrestlers,weight_id,tournament)
|
||||
wrestlers.each do |w|
|
||||
w.isWrestlingThisRound?(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def twoPools(wrestlers)
|
||||
|
||||
end
|
||||
|
||||
|
||||
def fourPools(wrestlers)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
def createMatch(w1,w2,round,tournament)
|
||||
|
||||
@match = Match.new
|
||||
@match.r_id = w1
|
||||
@match.g_id = w2
|
||||
@match.round = round
|
||||
@match.tournament_id = tournament
|
||||
@match.save
|
||||
end
|
||||
|
||||
end
|
||||
@@ -7,11 +7,14 @@ class Weight < ActiveRecord::Base
|
||||
def generatePool
|
||||
@wrestlers = Wrestler.where(weight_id: self.id)
|
||||
if self.pools == 1
|
||||
onePool(@wrestlers)
|
||||
@pool = Pool.new
|
||||
@pool.onePool(@wrestlers,self.id,self.tournament_id)
|
||||
elsif self.pools == 2
|
||||
|
||||
@pool = Pool.new
|
||||
@pool.twoPools(@wrestlers,self.id,self.tournament_id)
|
||||
elsif self.pools == 4
|
||||
|
||||
@pool = Pool.new
|
||||
@pool.fourPools(@wrestlers,self.id,self.tournament_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,16 +29,5 @@ class Weight < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def fourPool
|
||||
|
||||
end
|
||||
|
||||
def onePool(wrestlers)
|
||||
wrestlers.each do |wrestler|
|
||||
wrestler.poolNumber = 1
|
||||
wrestler.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -2,4 +2,14 @@ class Wrestler < ActiveRecord::Base
|
||||
belongs_to :school
|
||||
belongs_to :weight
|
||||
has_many :matches
|
||||
|
||||
def isWrestlingThisRound?(round)
|
||||
@r_id = Match.where(r_id: self.id, round: round)
|
||||
@g_id = Match.where(g_id: self.id, round: round)
|
||||
if @r_id or @g_id
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user