class V1::MatchScoreboardSerializer

Serialize a Match score with the following information:

Public Instance Methods

actions() click to toggle source

Serialize actions that may be executed on the match. See Match#valid_actions

  • Returns : Hash

Example

{
  start_game: true,
  discard_play: true,
  remove_last_change: true
}
# File app/serializers/v1/match_scoreboard_serializer.rb, line 42
def actions
  object.valid_actions
end
near_winners() click to toggle source

Serialize the id's of teams or players that are near to winning a set or the match. Player id's are serialized for singles matches; Team id's for doubles matches.

  • Returns : Hash

Example

(
  set: [10],
  match[]
}
# File app/serializers/v1/match_scoreboard_serializer.rb, line 57
def near_winners
  result = {
    set: [],
    match: []
  }
  first = object.first_team
  second = object.second_team
  last_set_var = object.last_set
  if first && second && last_set_var
    add_near_winner first, last_set_var, result
    add_near_winner second, last_set_var, result
  end

  result
end
servers() click to toggle source

Serialize a list of player id's that may serve the first or second game. (One of these players must be passed as a parameter when executing the :start_game action)

  • Returns :

    • an array of player ids

  • Example list before starting a doubles match:

    [10, 20, 30, 40]

  • Example list before starting the second game of a doubles match:

    [30, 40]

  • Example list before starting the first game of a singles match:

    [10, 20]

  • Value for all other cases:

    []

# File app/serializers/v1/match_scoreboard_serializer.rb, line 97
def servers
  result = []
  result.push(object.first_player_server.id) if object.first_player_server
  result.push(object.second_player_server.id) if object.second_player_server
  result
end
sets() click to toggle source

Serialize the sets of the match. See V1::MatchSetSerializer

  • Returns :

    • array of serialized sets

# File app/serializers/v1/match_scoreboard_serializer.rb, line 28
def sets
  V1::ApplicationArraySerializer.new(object.match_sets, each_serializer: V1::MatchSetSerializer)
end