class MatchPlay::NextServer
Class to determine which player serves next
Public Class Methods
new(match)
click to toggle source
-
Args
-
match
-> Match
-
# File app/models/concerns/match_play.rb, line 521 def initialize(match) @match = match end
Public Instance Methods
player()
click to toggle source
Determine the serving player. In a singles match, serving alternates between the two opponent players. In doubles, serving alternates between each opponent team and the players on each team.
-
Returns : Player
# File app/models/concerns/match_play.rb, line 529 def player # Count total games, ignoring tiebreaks games_played = match.set_games.all.reduce(0) do |sum, game| sum + (game.tiebreak? ? 0 : 1) end if match.doubles next_doubles_server games_played else next_singles_server games_played end end