Class: Bagel::Tennis::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/bagel/tennis/checker.rb

Constant Summary collapse

BREAK_POINT =
'BREAK POINT'
SET_POINT =
'SET POINT'
MATCH_POINT =
'MATCH POINT'
MINIMUM_POINTS_TO_WIN_GAME =
4
MINIMUM_POINTS_TO_WIN_TIEBREAK =
7
MINIMUM_GAMES_TO_WIN_SET =
6
SETS_TO_WIN_MATCH =
2
TIEBREAK_AT =
[ MINIMUM_GAMES_TO_WIN_SET, MINIMUM_GAMES_TO_WIN_SET ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sets:, points:, server:) ⇒ Checker

Returns a new instance of Checker.



17
18
19
20
# File 'lib/bagel/tennis/checker.rb', line 17

def initialize(sets:, points:, server:)
  @sets, @points, @server = sets, points, server
  @receiver = Player.opponent(server)
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



15
16
17
# File 'lib/bagel/tennis/checker.rb', line 15

def points
  @points
end

#receiverObject (readonly)

Returns the value of attribute receiver.



15
16
17
# File 'lib/bagel/tennis/checker.rb', line 15

def receiver
  @receiver
end

#serverObject (readonly)

Returns the value of attribute server.



15
16
17
# File 'lib/bagel/tennis/checker.rb', line 15

def server
  @server
end

#setsObject (readonly)

Returns the value of attribute sets.



15
16
17
# File 'lib/bagel/tennis/checker.rb', line 15

def sets
  @sets
end

Instance Method Details

#break_point?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/bagel/tennis/checker.rb', line 22

def break_point?
  next_point_wins_game?(receiver)
end

#match_point?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/bagel/tennis/checker.rb', line 30

def match_point?
  next_point_wins_match?(server) || next_point_wins_match?(receiver)
end

#set_point?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/bagel/tennis/checker.rb', line 26

def set_point?
  next_point_wins_set?(server) || next_point_wins_set?(receiver)
end

#tiebreak?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/bagel/tennis/checker.rb', line 34

def tiebreak?
  sets.last == Tennis::Checker::TIEBREAK_AT
end