Class: Bagel::Tennis::Outcome
- Inherits:
-
Object
- Object
- Bagel::Tennis::Outcome
- 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
-
#net ⇒ Object
readonly
Returns the value of attribute net.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#shot ⇒ Object
readonly
Returns the value of attribute shot.
-
#winner ⇒ Object
readonly
Returns the value of attribute winner.
Instance Method Summary collapse
- #ace? ⇒ Boolean
-
#initialize(winner:, reason:, shot:, net: nil) ⇒ Outcome
constructor
A new instance of Outcome.
- #p1_net_point? ⇒ Boolean
- #p1_won? ⇒ Boolean
- #p2_net_point? ⇒ Boolean
- #p2_won? ⇒ Boolean
- #unforced_error? ⇒ Boolean
- #winner? ⇒ Boolean
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
#net ⇒ Object (readonly)
Returns the value of attribute net.
11 12 13 |
# File 'lib/bagel/tennis/outcome.rb', line 11 def net @net end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
11 12 13 |
# File 'lib/bagel/tennis/outcome.rb', line 11 def reason @reason end |
#shot ⇒ Object (readonly)
Returns the value of attribute shot.
11 12 13 |
# File 'lib/bagel/tennis/outcome.rb', line 11 def shot @shot end |
#winner ⇒ Object (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
20 21 22 |
# File 'lib/bagel/tennis/outcome.rb', line 20 def ace? winner? && shot == SERVE end |
#p1_net_point? ⇒ 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
32 33 34 |
# File 'lib/bagel/tennis/outcome.rb', line 32 def p1_won? winner == Player.ONE end |
#p2_net_point? ⇒ 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
36 37 38 |
# File 'lib/bagel/tennis/outcome.rb', line 36 def p2_won? winner == Player.TWO end |
#unforced_error? ⇒ Boolean
28 29 30 |
# File 'lib/bagel/tennis/outcome.rb', line 28 def unforced_error? reason == UNFORCED_ERROR end |
#winner? ⇒ Boolean
24 25 26 |
# File 'lib/bagel/tennis/outcome.rb', line 24 def winner? reason == WINNER end |