Class: Bagel::Tennis::Serve

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

Constant Summary collapse

NO_FAULT =
0
DOUBLE_FAULT =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#faultsObject (readonly)

Returns the value of attribute faults.



6
7
8
# File 'lib/bagel/tennis/serve.rb', line 6

def faults
  @faults
end

#serverObject (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

Returns:

  • (Boolean)


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

def double_fault?
  faults == DOUBLE_FAULT
end

#no_faults?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/bagel/tennis/serve.rb', line 16

def no_faults?
  faults == NO_FAULT
end

#p1_serve?Boolean

Returns:

  • (Boolean)


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

def p1_serve?
  server?(Player.ONE)
end

#p2_serve?Boolean

Returns:

  • (Boolean)


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

def p2_serve?
  server?(Player.TWO)
end

#second_serve?Boolean

Returns:

  • (Boolean)


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

def second_serve?
  faults > NO_FAULT
end

#server?(player) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/bagel/tennis/serve.rb', line 12

def server?(player)
  server == player
end