diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/match.rb | 3 | ||||
-rw-r--r-- | app/models/tournament.rb | 12 | ||||
-rw-r--r-- | app/models/user.rb | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/app/models/match.rb b/app/models/match.rb index 35deb20..c596ced 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -5,4 +5,7 @@ class Match < ActiveRecord::Base belongs_to :winner, class_name: "Team" + def setup() + + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index ecd551b..22711b1 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -20,22 +20,22 @@ class Tournament < ActiveRecord::Base end def leave(user) - if players.include?(user) + if players.include?(user) && status == 0 players.delete(user) end end - def setup(tournament) - num_teams = (self.players.count/self.max_players_per_team).floor + def setup() + num_teams = (self.players.count/self.min_players_per_team).floor num_matches = num_teams - 1 for i in 1..num_matches - self.matches.create(name: "Match #{i}") + self.matches.create(name: "Match #{i}", status: 0) end match_num = 0 team_num = 0 - self.players.each_slice(tournament.max_players_per_team) do |players| + self.players.each_slice(min_players_per_team) do |players| self.matches[match_num].teams.push(Team.create(users: players)) - if (team_num != 0 and team_num % tournament.max_teams_per_match == 0) + if (team_num != 0 and team_num % max_teams_per_match == 0) match_num += 1 team_num = 0 else diff --git a/app/models/user.rb b/app/models/user.rb index 1d0879b..d1698bd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,8 @@ class User < ActiveRecord::Base has_and_belongs_to_many :teams has_many :sessions + apply_simple_captcha + before_save { self.email = email.downcase } before_save { self.user_name = user_name } |