2012-03-09 13:06:25 +00:00
|
|
|
class MashTournament < ActiveRecord::Base
|
2012-03-10 13:47:47 +00:00
|
|
|
belongs_to :requester
|
|
|
|
has_many :mashes
|
|
|
|
has_many :rounds, :class_name => 'MashTournamentRound'
|
|
|
|
|
|
|
|
def next_unplayed_mash
|
2012-03-12 04:18:42 +00:00
|
|
|
mash = self.mashes.unplayed.first
|
|
|
|
if not mash
|
|
|
|
filled = self.builder.fill_in_next_round
|
|
|
|
if filled
|
|
|
|
return self.mashes.unplayed.first
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return mash
|
|
|
|
end
|
2012-03-10 13:47:47 +00:00
|
|
|
end
|
|
|
|
|
2012-03-13 03:28:38 +00:00
|
|
|
def total_rounds_options
|
|
|
|
@total_rounds_options ||= [3, 4, 5, 6, 7]
|
|
|
|
end
|
|
|
|
|
2012-03-10 13:47:47 +00:00
|
|
|
def done?
|
2012-03-12 04:18:42 +00:00
|
|
|
self.rounds.collect(&:done?).uniq == [true]
|
2012-03-10 13:47:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def round(number = 0)
|
|
|
|
MashTournamentRound.find_by_mash_tournament_id(self.id,
|
|
|
|
:conditions => {:number => number}
|
|
|
|
)
|
|
|
|
end
|
2012-03-12 04:18:42 +00:00
|
|
|
|
|
|
|
def builder
|
|
|
|
MashTournamentBuilder.new(
|
|
|
|
self, MashTournament, MashTournamentRound, Map, Mash
|
|
|
|
)
|
|
|
|
end
|
2012-03-09 13:06:25 +00:00
|
|
|
end
|