mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
29 lines
501 B
Ruby
29 lines
501 B
Ruby
class School < ActiveRecord::Base
|
|
belongs_to :tournament
|
|
has_many :wrestlers, dependent: :destroy
|
|
has_many :deductedPoints, through: :wrestlers
|
|
|
|
|
|
#calculate score here
|
|
|
|
def calcScore
|
|
totalWrestlerPoints - totalDeductedPoints
|
|
end
|
|
|
|
def totalWrestlerPoints
|
|
points = 0
|
|
self.wrestlers.each do |w|
|
|
points = points + w.totalTeamPoints
|
|
end
|
|
points
|
|
end
|
|
|
|
def totalDeductedPoints
|
|
points = 0
|
|
self.deductedPoints.each do |d|
|
|
points = points + d.points
|
|
end
|
|
points
|
|
end
|
|
end
|