1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-31 19:45:45 +00:00
Files
wrestlingdev.com/app/models/wrestler.rb
Jacob Cody Wimer 9c5c12c413 Matchups_array completely removed. I do not know why has_many matches
does not work in tournaments. The solution was to add a matches
method.
2015-04-27 09:50:41 -04:00

55 lines
1.0 KiB
Ruby

class Wrestler < ActiveRecord::Base
belongs_to :school
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
def generatePoolNumber
@pool = self.weight.returnPoolNumber(self)
return @pool
end
def boutByRound(round,matches)
@match = allMatches.select{|m| m.round == round}.first
if @match.blank?
return "BYE"
else
return @match.boutNumber
end
end
def allMatches
@matches = Match.where("w1 = ? or w2 = ?",self.id,self.id)
return @matches
end
def seasonWinPercentage
@win = self.season_win.to_f
@loss = self.season_loss.to_f
if @win > 0 and @loss != nil
@matchTotal = @win + @loss
@percentageDec = @win / @matchTotal
@percentage = @percentageDec * 100
return @percentage.to_i
elsif self.season_win == 0
return 0
elsif self.season_win == nil or self.season_loss == nil
return 0
end
end
end