Getting at least one tournament working!
This commit is contained in:
@@ -5,11 +5,9 @@ class Mash < ActiveRecord::Base
|
||||
has_one :tournament, :class_name => 'MashTournament'
|
||||
has_one :round, :class_name => 'MashTournamentRound'
|
||||
|
||||
named_scope :unplayed, {
|
||||
:conditions => %{
|
||||
named_scope :unplayed, :conditions => [%{
|
||||
winner_id IS NULL
|
||||
AND map_a_id IS NOT NULL
|
||||
AND map_b_id IS NOT NULL
|
||||
}
|
||||
}
|
||||
}]
|
||||
end
|
||||
|
@@ -4,11 +4,21 @@ class MashTournament < ActiveRecord::Base
|
||||
has_many :rounds, :class_name => 'MashTournamentRound'
|
||||
|
||||
def next_unplayed_mash
|
||||
self.mashes.unplayed.first
|
||||
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
|
||||
end
|
||||
|
||||
def done?
|
||||
true
|
||||
self.rounds.collect(&:done?).uniq == [true]
|
||||
end
|
||||
|
||||
def round(number = 0)
|
||||
@@ -16,4 +26,10 @@ class MashTournament < ActiveRecord::Base
|
||||
:conditions => {:number => number}
|
||||
)
|
||||
end
|
||||
|
||||
def builder
|
||||
MashTournamentBuilder.new(
|
||||
self, MashTournament, MashTournamentRound, Map, Mash
|
||||
)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user