Class: Superbowl::Grid
- Inherits:
-
Object
- Object
- Superbowl::Grid
- Defined in:
- lib/superbowl/grid.rb
Instance Attribute Summary collapse
-
#squares ⇒ Object
readonly
Returns the value of attribute squares.
Class Method Summary collapse
Instance Method Summary collapse
- #contestants(box_score_history) ⇒ Object
-
#initialize(squares) ⇒ Grid
constructor
A new instance of Grid.
Constructor Details
#initialize(squares) ⇒ Grid
Returns a new instance of Grid.
12 13 14 |
# File 'lib/superbowl/grid.rb', line 12 def initialize(squares) @squares = squares end |
Instance Attribute Details
#squares ⇒ Object (readonly)
Returns the value of attribute squares.
6 7 8 |
# File 'lib/superbowl/grid.rb', line 6 def squares @squares end |
Class Method Details
.parse(filename) ⇒ Object
8 9 10 |
# File 'lib/superbowl/grid.rb', line 8 def self.parse(filename) new(CSV.open(filename, col_sep: "\t").to_a) end |
Instance Method Details
#contestants(box_score_history) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/superbowl/grid.rb', line 16 def contestants(box_score_history) contestants_by_name = {} @squares.each_with_index do |row, row_index| row.each_with_index do |owner, col_index| c = contestants_by_name[owner] ||= Contestant.new(owner, 0, 0) c.expected_payout += box_score_history.ratio(row_index, col_index) * 1000 c.num_squares += 1 end end contestants_by_name.values.sort_by(&:expected_payout).reverse end |