Class: Bagel::Tennis::Score
- Inherits:
-
Object
- Object
- Bagel::Tennis::Score
- Defined in:
- lib/bagel/tennis/score.rb
Instance Attribute Summary collapse
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#sets ⇒ Object
readonly
Returns the value of attribute sets.
Instance Method Summary collapse
- #break_point? ⇒ Boolean
- #context ⇒ Object
- #id ⇒ Object
-
#initialize(sets:, points: nil, server: nil) ⇒ Score
constructor
A new instance of Score.
- #match_point? ⇒ Boolean
- #server?(player_id) ⇒ Boolean
- #set_number ⇒ Object
- #set_point? ⇒ Boolean
- #set_score ⇒ Object
- #tiebreak? ⇒ Boolean
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
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
4 5 6 |
# File 'lib/bagel/tennis/score.rb', line 4 def checker @checker end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
3 4 5 |
# File 'lib/bagel/tennis/score.rb', line 3 def points @points end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
4 5 6 |
# File 'lib/bagel/tennis/score.rb', line 4 def server @server end |
#sets ⇒ Object (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
35 36 37 |
# File 'lib/bagel/tennis/score.rb', line 35 def break_point? checker.break_point? end |
#context ⇒ Object
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 |
#id ⇒ Object
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
43 44 45 |
# File 'lib/bagel/tennis/score.rb', line 43 def match_point? checker.match_point? end |
#server?(player_id) ⇒ Boolean
23 24 25 |
# File 'lib/bagel/tennis/score.rb', line 23 def server?(player_id) server == player_id end |
#set_number ⇒ Object
27 28 29 |
# File 'lib/bagel/tennis/score.rb', line 27 def set_number sets.count end |
#set_point? ⇒ Boolean
39 40 41 |
# File 'lib/bagel/tennis/score.rb', line 39 def set_point? checker.set_point? end |
#set_score ⇒ Object
31 32 33 |
# File 'lib/bagel/tennis/score.rb', line 31 def set_score sets.last end |
#tiebreak? ⇒ Boolean
47 48 49 |
# File 'lib/bagel/tennis/score.rb', line 47 def tiebreak? checker.tiebreak? end |