Class: League
- Inherits:
-
Object
- Object
- League
- Defined in:
- lib/league.rb
Instance Attribute Summary collapse
-
#games ⇒ Object
Returns the value of attribute games.
-
#score_hash ⇒ Object
Returns the value of attribute score_hash.
Instance Method Summary collapse
- #adjust_score(adjustment_data) ⇒ Object
-
#initialize(games_array) ⇒ League
constructor
A new instance of League.
- #results ⇒ Object
Constructor Details
permalink #initialize(games_array) ⇒ League
Returns a new instance of League.
6 7 8 9 |
# File 'lib/league.rb', line 6 def initialize(games_array) @games = games_array @score_hash = {} end |
Instance Attribute Details
permalink #games ⇒ Object
Returns the value of attribute games.
4 5 6 |
# File 'lib/league.rb', line 4 def games @games end |
permalink #score_hash ⇒ Object
Returns the value of attribute score_hash.
4 5 6 |
# File 'lib/league.rb', line 4 def score_hash @score_hash end |
Instance Method Details
permalink #adjust_score(adjustment_data) ⇒ Object
[View source]
25 26 27 28 29 30 31 32 33 |
# File 'lib/league.rb', line 25 def adjust_score(adjustment_data) adjustment_data.each do |key, value| if @score_hash.key?(key) @score_hash[key] += value else @score_hash[key] = value end end end |
permalink #results ⇒ Object
[View source]
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/league.rb', line 11 def results @games.each do |game| adjust_score(game.adjustment) end result_array = @score_hash.sort_by { |k, v| k } result_array = result_array.reverse result_array = result_array.sort_by { |k, v| v } result_array = result_array.reverse result_array.each_with_index.map do |item, index| "#{index + 1}. #{item[0]}, #{item[1]} #{item[1] > 1 || item[1] == 0 ? 'pts' : 'pt'}" end end |