Class: Bagel::Tennis::Outcome

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

Constant Summary collapse

SERVE =
'S'
FOREHAND =
'FH'
BACKHAND =
'BH'
WINNER =
'W'
FORCED_ERROR =
'FE'
UNFORCED_ERROR =
'UE'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(winner:, reason:, shot:, net: nil) ⇒ Outcome

Returns a new instance of Outcome.



13
14
15
16
17
18
# File 'lib/bagel/tennis/outcome.rb', line 13

def initialize(winner:, reason:, shot:, net: nil)
  @winner = winner
  @reason = reason
  @shot = shot
  @net = net
end

Instance Attribute Details

#netObject (readonly)

Returns the value of attribute net.



11
12
13
# File 'lib/bagel/tennis/outcome.rb', line 11

def net
  @net
end

#reasonObject (readonly)

Returns the value of attribute reason.



11
12
13
# File 'lib/bagel/tennis/outcome.rb', line 11

def reason
  @reason
end

#shotObject (readonly)

Returns the value of attribute shot.



11
12
13
# File 'lib/bagel/tennis/outcome.rb', line 11

def shot
  @shot
end

#winnerObject (readonly)

Returns the value of attribute winner.



11
12
13
# File 'lib/bagel/tennis/outcome.rb', line 11

def winner
  @winner
end

Instance Method Details

#ace?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/bagel/tennis/outcome.rb', line 20

def ace?
  winner? && shot == SERVE
end

#p1_net_point?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bagel/tennis/outcome.rb', line 40

def p1_net_point?
  net && !net[Player.index(Player.ONE)].nil?
end

#p1_won?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/bagel/tennis/outcome.rb', line 32

def p1_won?
  winner == Player.ONE
end

#p2_net_point?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bagel/tennis/outcome.rb', line 44

def p2_net_point?
  net && !net[Player.index(Player.TWO)].nil?
end

#p2_won?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/bagel/tennis/outcome.rb', line 36

def p2_won?
  winner == Player.TWO
end

#unforced_error?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/bagel/tennis/outcome.rb', line 28

def unforced_error?
  reason == UNFORCED_ERROR
end

#winner?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/bagel/tennis/outcome.rb', line 24

def winner?
  reason == WINNER
end