Class: Bagel::Tennis::Score

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sets:, points: nil, server: nil) ⇒ Score

Returns a new instance of Score.



6
7
8
9
10
# File 'lib/bagel/tennis/score.rb', line 6

def initialize(sets:, points: nil, server: nil)
  @sets, @points = sets, points
  @server = server
  @checker = Tennis::Checker.new(sets: sets, points: points, server: server)
end

Instance Attribute Details

#checkerObject (readonly)

Returns the value of attribute checker.



4
5
6
# File 'lib/bagel/tennis/score.rb', line 4

def checker
  @checker
end

#pointsObject (readonly)

Returns the value of attribute points.



3
4
5
# File 'lib/bagel/tennis/score.rb', line 3

def points
  @points
end

#serverObject (readonly)

Returns the value of attribute server.



4
5
6
# File 'lib/bagel/tennis/score.rb', line 4

def server
  @server
end

#setsObject (readonly)

Returns the value of attribute sets.



3
4
5
# File 'lib/bagel/tennis/score.rb', line 3

def sets
  @sets
end

Instance Method Details

#break_point?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/bagel/tennis/score.rb', line 35

def break_point?
  checker.break_point?
end

#contextObject



16
17
18
19
20
21
# File 'lib/bagel/tennis/score.rb', line 16

def context
  return nil if server.nil?
  return Tennis::Checker::MATCH_POINT if match_point?
  return Tennis::Checker::SET_POINT if set_point?
  return Tennis::Checker::BREAK_POINT if break_point?
end

#idObject



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

def id
  id_parts.map { |i| i.to_s.rjust(2, '0') }.join('-')
end

#match_point?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/bagel/tennis/score.rb', line 43

def match_point?
  checker.match_point?
end

#server?(player_id) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/bagel/tennis/score.rb', line 23

def server?(player_id)
  server == player_id
end

#set_numberObject



27
28
29
# File 'lib/bagel/tennis/score.rb', line 27

def set_number
  sets.count
end

#set_point?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/bagel/tennis/score.rb', line 39

def set_point?
  checker.set_point?
end

#set_scoreObject



31
32
33
# File 'lib/bagel/tennis/score.rb', line 31

def set_score
  sets.last
end

#tiebreak?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/bagel/tennis/score.rb', line 47

def tiebreak?
  checker.tiebreak?
end