class V1::MatchSerializer

Serialize a Match with the following attributes:

Public Instance Methods

attributes() click to toggle source

Indicate dynamic attributes to the serializer. For a doubles match, serialize first and second players. For a singles match, serialize the first and second teams.

  • Returns : Hash of attributes

Calls superclass method
# File app/serializers/v1/match_serializer.rb, line 35
def attributes
  data = super
  if object.doubles
    data[:first_team] = first_team
    data[:second_team] = second_team
  else
    data[:first_player] = first_player
    data[:second_player] = second_player
  end
  data
end
first_player() click to toggle source

Serialize the first player

# File app/serializers/v1/match_serializer.rb, line 51
def first_player
  V1::PlayerSerializer.new(object.first_team.first_player)
end
first_team() click to toggle source

Serialize the first team

# File app/serializers/v1/match_serializer.rb, line 59
def first_team
  V1::TeamSerializer.new(object.first_team)
end
second_player() click to toggle source

Serialize the second player

# File app/serializers/v1/match_serializer.rb, line 67
def second_player
  V1::PlayerSerializer.new(object.second_team.first_player)
end
second_team() click to toggle source

Serialize the second team. See V1::OpponentTeamSerializer.

# File app/serializers/v1/match_serializer.rb, line 75
def second_team
  V1::TeamSerializer.new(object.second_team)
end
winner() click to toggle source

Serialize the player or team id of the match winner, if any.

  • Returns : id

# File app/serializers/v1/match_serializer.rb, line 21
def winner
  if object.team_winner.nil?
    nil
  else
    opponent_id object.team_winner
  end
end

Protected Instance Methods

opponent_id(team) click to toggle source

Get the id for an opponent in a match. For a doubles match, get a team id. For a singles match, get a player id

  • Args :

    • team -> opponent Team

  • Returns : id

# File app/serializers/v1/match_serializer.rb, line 87
def opponent_id(team)
  if object.doubles
    team.id
  else
    team.first_player.id
  end
end