1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-19 05:43:17 +00:00

rough cut of getting rid of the matches collection being passed around

Associated Weight and Match-- the FK already existed in the domain
Reduced argument counts on assignLoserNames and assignBouts; trying to pass a Tournament around more
This was a tough nut to crack.  Looking back, I tried to eat too much of the horse at once on this refactor.
This commit is contained in:
RJ Osborne
2015-05-26 15:09:48 -04:00
parent 20ef048f48
commit c041286943
6 changed files with 64 additions and 85 deletions

View File

@@ -1,27 +1,16 @@
class Boutgen
def matchesByRound(round, matches)
@matches = matches.select {|m| m.round == round}
return @matches
def matchesByRound(tournament, round)
tournament.matches.joins(:weight).where(round: round).order("weights.max")
end
def giveBout(matches)
@matches = matches.sort_by{|x|[x.weight_max]}
@matches.each_with_index do |m, i|
@bout = m.round * 1000 + i
m.bout_number = @bout
def assignBouts(tournament)
bout_counts = Hash.new(0)
matches = tournament.matches.each do |m|
m.bout_number = m.round * 1000 + bout_counts[m.round]
bout_counts[m.round] += 1
m.save!
end
return @matches
end
def assignBouts(matches,weights)
@round = 1
until matchesByRound(@round, matches).blank? do
@matches = matchesByRound(@round, matches)
giveBout(@matches)
@round += 1
end
return matches
end
end
end