Class: Bagel::Tennis::Serve
- Inherits:
-
Object
- Object
- Bagel::Tennis::Serve
- Defined in:
- lib/bagel/tennis/serve.rb
Constant Summary collapse
- NO_FAULT =
0
- DOUBLE_FAULT =
2
Instance Attribute Summary collapse
-
#faults ⇒ Object
readonly
Returns the value of attribute faults.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #double_fault? ⇒ Boolean
-
#initialize(server:, faults:) ⇒ Serve
constructor
A new instance of Serve.
- #no_faults? ⇒ Boolean
- #p1_serve? ⇒ Boolean
- #p2_serve? ⇒ Boolean
- #second_serve? ⇒ Boolean
- #server?(player) ⇒ Boolean
Constructor Details
#initialize(server:, faults:) ⇒ Serve
Returns a new instance of Serve.
8 9 10 |
# File 'lib/bagel/tennis/serve.rb', line 8 def initialize(server:, faults:) @server, @faults = server, faults end |
Instance Attribute Details
#faults ⇒ Object (readonly)
Returns the value of attribute faults.
6 7 8 |
# File 'lib/bagel/tennis/serve.rb', line 6 def faults @faults end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
6 7 8 |
# File 'lib/bagel/tennis/serve.rb', line 6 def server @server end |
Instance Method Details
#double_fault? ⇒ Boolean
24 25 26 |
# File 'lib/bagel/tennis/serve.rb', line 24 def double_fault? faults == DOUBLE_FAULT end |
#no_faults? ⇒ Boolean
16 17 18 |
# File 'lib/bagel/tennis/serve.rb', line 16 def no_faults? faults == NO_FAULT end |
#p1_serve? ⇒ Boolean
28 29 30 |
# File 'lib/bagel/tennis/serve.rb', line 28 def p1_serve? server?(Player.ONE) end |
#p2_serve? ⇒ Boolean
32 33 34 |
# File 'lib/bagel/tennis/serve.rb', line 32 def p2_serve? server?(Player.TWO) end |
#second_serve? ⇒ Boolean
20 21 22 |
# File 'lib/bagel/tennis/serve.rb', line 20 def second_serve? faults > NO_FAULT end |
#server?(player) ⇒ Boolean
12 13 14 |
# File 'lib/bagel/tennis/serve.rb', line 12 def server?(player) server == player end |