class League

Attributes

games[RW]
score_hash[RW]

Public Class Methods

new(games_array) click to toggle source
# File lib/league.rb, line 6
def initialize(games_array)
  @games = games_array
  @score_hash = {}
end

Public Instance Methods

adjust_score(adjustment_data) click to toggle source
# 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
results() click to toggle source
# 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