1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-10 23:53:06 +00:00

Made pool and bout classes. Still need to fix bouts doubling on every

refresh of upcoming matches view
This commit is contained in:
2014-12-15 13:12:39 -05:00
parent 73edb4a765
commit 1899218798
6 changed files with 54 additions and 43 deletions

11
app/models/bout.rb Normal file
View File

@@ -0,0 +1,11 @@
class Bout
attr_accessor :w1, :w2, :tournament_id
def self.all
ObjectSpace.each_object(self).to_a
end
def self.count
all.count
end
end

30
app/models/pool.rb Normal file
View File

@@ -0,0 +1,30 @@
class Pool
def createPool(tournament)
@weights = Weight.where(tournament_id: tournament)
@weights.each do |weight|
roundRobin(weight,tournament)
end
end
def createBout(wrestler,tournament)
@bout = Bout.new
@bout.w1 = wrestler.id
@bout.tournament_id = tournament
end
def roundRobin(weight,tournament)
@wrestlers = Wrestler.where(weight_id: weight)
@wrestlers.each do |wrestler|
createBout(wrestler,tournament)
end
end
def self.all
ObjectSpace.each_object(self).to_a
end
def self.count
all.count
end
end

View File

@@ -3,4 +3,11 @@ class Tournament < ActiveRecord::Base
has_many :weights, dependent: :destroy
has_many :matches, dependent: :destroy
has_many :mats, dependent: :destroy
def bouts
@pool = Pool.new
@pool.createPool(self.id)
@bouts = Bout.all
return @bouts
end
end

View File

@@ -1,4 +1,6 @@
class Weight < ActiveRecord::Base
belongs_to :tournament
has_many :wrestlers, dependent: :destroy
end