1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-07 23:17:25 +00:00

Added head to head pool winner and tests

This commit is contained in:
2015-11-10 02:58:52 +00:00
parent 201d8d1f62
commit 34a04be4bf
4 changed files with 106 additions and 5 deletions

46
app/models/poolorder.rb Normal file
View File

@@ -0,0 +1,46 @@
class Poolorder
def initialize(wrestlers)
@wrestlers = wrestlers
end
attr_accessor :wrestlersWithSamePoints
def getPoolOrder
setOriginalPoints
until checkForTieBreakers == false
breakTie
end
@wrestlers.sort_by{|w| w.poolAdvancePoints}.reverse!
end
def setOriginalPoints
@wrestlers.each do |w|
w.poolAdvancePoints = w.poolWins.size
end
end
def checkForTieBreakers
@wrestlers.each do |w|
self.wrestlersWithSamePoints = @wrestlers.select{|wr| wr.poolAdvancePoints == w.poolAdvancePoints}
if self.wrestlersWithSamePoints.size > 1
return true
end
end
return false
end
def breakTie
headToHead
end
def headToHead
self.wrestlersWithSamePoints.each do |wr|
@otherWrestlers = self.wrestlersWithSamePoints.select{|w| w.id != wr.id}
@otherWrestlers.each do |ow|
if wr.matchAgainst(ow).first.winner_id == wr.id
wr.poolAdvancePoints = wr.poolAdvancePoints + 1
end
end
end
end
end