Class: Playoffs::BestOf
- Inherits:
-
Object
- Object
- Playoffs::BestOf
- 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
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(total = 7) ⇒ BestOf
constructor
A new instance of BestOf.
- #to_s ⇒ Object
- #to_win ⇒ Object
Constructor Details
#initialize(total = 7) ⇒ BestOf
Returns a new instance of BestOf.
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
#total ⇒ Object (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_s ⇒ Object
28 29 30 |
# File 'lib/playoffs/best_of.rb', line 28 def to_s "#{self.class.to_s.split('::').last}::#{total}" end |
#to_win ⇒ Object
23 24 25 |
# File 'lib/playoffs/best_of.rb', line 23 def to_win (total / 2.0).ceil end |