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:
46
app/models/poolorder.rb
Normal file
46
app/models/poolorder.rb
Normal 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
|
||||
Reference in New Issue
Block a user