diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/tournament.rb | 16 | ||||
-rw-r--r-- | app/models/tournament_stage.rb | 52 |
2 files changed, 30 insertions, 38 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 7460a7d..61b4700 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -6,6 +6,8 @@ class Tournament < ActiveRecord::Base has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" + # Settings ################################################################# + def settings @settings ||= Settings.new(self) end @@ -57,10 +59,14 @@ class Tournament < ActiveRecord::Base end end + # Misc. #################################################################### + def open? return true end + # Joining/Leaving ########################################################## + def joinable_by?(user) return (open? and user.can?(:join_tournament) and !players.include?(user)) end @@ -77,4 +83,14 @@ class Tournament < ActiveRecord::Base players.delete(user) end end + + # Configured methods ####################################################### + + def scoring + @scoring ||= "Scoring::#{self.scoring_method.camelcase}".constantize + end + + def sampling + @sampling ||= "Sampling::#{self.sampling_method.camelcase}".constantize + end end diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb index 0775305..9352137 100644 --- a/app/models/tournament_stage.rb +++ b/app/models/tournament_stage.rb @@ -2,6 +2,7 @@ class TournamentStage < ActiveRecord::Base belongs_to :tournament has_many :matches + # A 1-indexed hash of matches def matches_ordered h = {} i = 1 @@ -13,57 +14,32 @@ class TournamentStage < ActiveRecord::Base end def create_matches - set_scheduling - @scheduling.create_matches + scheduling.create_matches end def to_svg(highlight_user) - set_scheduling - return @scheduling.graph(highlight_user) + return scheduling.graph(highlight_user) end - def pair - set_pairing - return @pairing.pair(matches, players) + def seed + return seeding.seed.pair(matches, players) end - def score - set_scoring - #populating the user scores in the database form what you get from @scoring.score(match, interface) - end + # Accessors to the configured methods - #populate the statistics interface (with populating method) - def populate - set_populating - #? + def scoring + @scoring ||= tournament.scoring end - private - def set_scheduling - if @scheduling.nil? - @scheduling = "Scheduling::#{self.scheduling.capitalize}".constantize.new(self) - end - return @scheduling - end - - private - def set_pairing - if @pairing.nil? - if(@tournament.randomized_teams) - @pairing = "Pairing::RandomPairing" - #elsif(setTeams) - #@pairing = Pre built - #return @pairing - end - end - return @pairing + def sampling + @sampling ||= tournament.sampling end - private - def set_scoring + def scheduling + @scheduling ||= "Scheduling::#{self.scheduling_method.camelcase}".constantize.new(self) end - private - def set_populating + def seeding + @seeding ||= "Seeding::#{self.seeding_method.camelcase}".constantize.new(self) end end |