Class: Playoffs::BestOf

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/playoffs/best_of.rb

Overview

Contains rules for how many total a series can be.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total = 7) ⇒ BestOf

Returns a new instance of BestOf.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
# File 'lib/playoffs/best_of.rb', line 13

def initialize(total = 7)
  raise ArgumentError, 'total has to be positive' unless total.positive?
  raise ArgumentError, 'total has to be odd' unless total.odd?

  @total = total

  freeze
end

Instance Attribute Details

#totalObject (readonly)

Returns the value of attribute total.



10
11
12
# File 'lib/playoffs/best_of.rb', line 10

def total
  @total
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



33
34
35
# File 'lib/playoffs/best_of.rb', line 33

def ==(other)
  total == other.total
end

#to_sObject



28
29
30
# File 'lib/playoffs/best_of.rb', line 28

def to_s
  "#{self.class.to_s.split('::').last}::#{total}"
end

#to_winObject



23
24
25
# File 'lib/playoffs/best_of.rb', line 23

def to_win
  (total / 2.0).ceil
end