1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Simplify construction a bit on some methods

This commit is contained in:
R.J. Osborne
2015-05-19 22:36:30 -04:00
parent 80dee9c234
commit 0e954c1789
3 changed files with 33 additions and 42 deletions

View File

@@ -3,7 +3,7 @@ class Pool
@pools = weight.pools
@pool = 1
while @pool <= @pools
matches = roundRobin(weight.wrestlers, weight, tournament , matches)
matches = roundRobin(weight.wrestlers, weight, tournament, matches)
@pool += 1
end
return matches
@@ -12,19 +12,16 @@ class Pool
def roundRobin(wrestlers,weight,tournament,matches)
@wrestlers = wrestlers.select{|w| w.generatePoolNumber == @pool}.to_a
@poolMatches = RoundRobinTournament.schedule(@wrestlers).reverse
@poolMatches.each_with_index do |b,index|
@poolMatches.each_with_index do |b, index|
round = index + 1
@bout = b.map
@bout.each do |bout|
if bout[0] != nil and bout[1] != nil
@match = Match.new
@match.w1 = bout[0].id
@match.w2 = bout[1].id
@match.weight_id = weight.id
@match.round = index + 1
@match = Match.new(w1: bout[0].id, w2: bout[1].id, weight_id: weight.id, round: round)
matches << @match
end
end
end
return matches
matches
end
end

View File

@@ -3,23 +3,22 @@ class Wrestler < ActiveRecord::Base
belongs_to :weight
has_one :tournament, through: :weight
attr_accessor :poolNumber
before_save do
self.tournament.destroyAllMatches
end
def isWrestlingThisRound(matchRound)
if allMatches.blank?
return false
else
return true
end
end
end
def generatePoolNumber
@pool = self.weight.returnPoolNumber(self)
return @pool
end
def boutByRound(round,matches)
@@ -30,7 +29,7 @@ class Wrestler < ActiveRecord::Base
return @match.bout_number
end
end
def allMatches
@matches = Match.where("w1 = ? or w2 = ?",self.id,self.id)
return @matches
@@ -48,7 +47,7 @@ class Wrestler < ActiveRecord::Base
elsif self.season_win == 0
return 0
elsif self.season_win == nil or self.season_loss == nil
return 0
return 0
end
end
end