mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-19 22:01:31 +00:00
Moved match generation to a class and added tournament_type to tournaments.
This commit is contained in:
@@ -5,48 +5,31 @@ class Tournament < ActiveRecord::Base
|
||||
has_many :wrestlers, through: :weights
|
||||
|
||||
|
||||
def tournament_types
|
||||
["Pool to bracket"]
|
||||
end
|
||||
|
||||
def matches
|
||||
@matches = Match.where(tournament_id: self.id)
|
||||
end
|
||||
|
||||
|
||||
|
||||
def upcomingMatches
|
||||
if matches.nil?
|
||||
return matches
|
||||
else
|
||||
@matches = generateMatchups
|
||||
saveMatchups(@matches)
|
||||
return @matches
|
||||
generateMatchups
|
||||
return matches
|
||||
end
|
||||
end
|
||||
|
||||
def generateMatchups
|
||||
destroyAllMatches
|
||||
@matches = []
|
||||
self.weights.map.sort_by{|x|[x.max]}.each do |weight|
|
||||
@matches = weight.generateMatchups(@matches)
|
||||
end
|
||||
@matches = assignBouts(@matches)
|
||||
@matches = Losernamegen.new.assignLoserNames(@matches,self.weights)
|
||||
return @matches
|
||||
end
|
||||
|
||||
def assignBouts(matches)
|
||||
@bouts = Boutgen.new
|
||||
@matches = @bouts.assignBouts(matches,self.weights)
|
||||
return @matches
|
||||
end
|
||||
|
||||
def saveMatchups(matches)
|
||||
matches.each do |m|
|
||||
m.tournament_id = self.id
|
||||
m.save
|
||||
end
|
||||
@matches = Tournamentmatchgen.new.genMatches(self)
|
||||
end
|
||||
|
||||
def destroyAllMatches
|
||||
matches.each do |m|
|
||||
m.destroy
|
||||
end
|
||||
matches.destroy_all
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user