Getting at least one tournament working!

This commit is contained in:
Dan Buch
2012-03-12 00:18:42 -04:00
parent 73cff897a3
commit d08362326d
10 changed files with 66 additions and 79 deletions

View File

@@ -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

View File

@@ -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