1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 04:35:26 +00:00
Files
wrestlingdev.com/app/models/tournament.rb
RJ Osborne 062396da0a A Tournament can now generate its own matches.
This was again extracted as a module.  Modules get more powerful as they get more generic.  This is far from generic.
2015-05-27 23:57:37 -04:00

49 lines
923 B
Ruby

class Tournament < ActiveRecord::Base
include GeneratesLoserNames
include GeneratesTournamentMatches
has_many :schools, dependent: :destroy
has_many :weights, dependent: :destroy
has_many :mats, dependent: :destroy
has_many :wrestlers, through: :weights
has_many :matches, dependent: :destroy
def tournament_types
["Pool to bracket"]
end
def createCustomWeights(value)
weights.destroy_all
if value == 'hs'
Weight::HS_WEIGHT_CLASSES.each do |w|
weights.create(max: w)
end
else
raise "Unspecified behavior"
end
end
def upcomingMatches
matches
end
def destroyAllMatches
matches.destroy_all
end
def matchesByRound(round)
matches.joins(:weight).where(round: round).order("weights.max")
end
def assignBouts
bout_counts = Hash.new(0)
matches.each do |m|
m.bout_number = m.round * 1000 + bout_counts[m.round]
bout_counts[m.round] += 1
m.save!
end
end
end