class Big3::League
Attributes
game_ids[RW]
game_stats[RW]
games[RW]
p_s[RW]
player_name[RW]
player_stats[RW]
t_s[RW]
team_name[RW]
Public Class Methods
new(args={})
click to toggle source
# File lib/big_3/league.rb, line 9 def initialize(args={}) @player_name = args[:player_name] ||= nil @team_name = args[:team_name] ||= nil retrieve_game_data end
Public Instance Methods
add_game(scores, away_team, home_team, stats, season_team, location, game_count)
click to toggle source
# File lib/big_3/league.rb, line 94 def add_game(scores, away_team, home_team, stats, season_team, location, game_count) add_scoring(scores, away_team, home_team) add_stats(scores, away_team, home_team, stats, location, game_count) add_stats_to_season(stats, season_team) end
add_players(players, team_name, league)
click to toggle source
# File lib/big_3/league.rb, line 178 def add_players(players, team_name, league) players.each do |player| team_name = team_name.sub("3s","3's") player_name = player['@name'] player_name = player_name.sub("Mahmoud-","Mahmoud ") if teams.include?(player_name) || player_name.include?("TEAM") || league[team_name].include?(player_name) next else league[team_name] << player_name end end end
add_scoring(scores, away_team, home_team)
click to toggle source
# File lib/big_3/league.rb, line 68 def add_scoring(scores, away_team, home_team) scores["first half"] = { "home" => home_team['linescore']["lineprd"][0]["@score"], "away" => away_team['linescore']["lineprd"][0]["@score"] } scores["second half"] = { "home" => home_team['linescore']["lineprd"][1]["@score"], "away" => away_team['linescore']["lineprd"][1]["@score"] } scores["final"] = { "home" => home_team['linescore']["@score"], "away" => away_team['linescore']["@score"] } end
add_stats(scores, away_team, home_team, stats, location, game_count)
click to toggle source
# File lib/big_3/league.rb, line 111 def add_stats(scores, away_team, home_team, stats, location, game_count) from_both_teams = { "home" => home_team["totals"]["stats"], "away" => away_team["totals"]["stats"] } stats["games"] << { "matchup" => "#{home_team["@name"]} vs #{away_team["@name"]}", "home team" => home_team["@name"], "away team" => away_team["@name"], "scores" => scores, "stats" => from_both_teams, "location" => location, "game_number" => game_count.to_s } end
add_stats_to_season(stats, team)
click to toggle source
# File lib/big_3/league.rb, line 79 def add_stats_to_season(stats, team) team["totals"]["stats"].each do |k, v| v = v.to_f stats["season"][k] += v end end
filter_team_stats(scores, away_team, home_team, stats, season_team, location, game_count)
click to toggle source
# File lib/big_3/league.rb, line 128 def filter_team_stats(scores, away_team, home_team, stats, season_team, location, game_count) stats["name"] = team_name.split.map(&:capitalize).join(' ') if names_match?(away_team, team_name) add_game(scores, away_team, home_team, stats, season_team, location, game_count) elsif names_match?(home_team, team_name) add_game(scores, away_team, home_team, stats, season_team, location, game_count) end end
find_rosters()
click to toggle source
# File lib/big_3/league.rb, line 169 def find_rosters @rosters = Hash.new { |h, k| h[k] = [] } game_stats.each do |team| add_players(team.away_team_players, team.away_team_name, rosters) add_players(team.home_team_players, team.home_team_name, rosters) end @rosters end
find_season_averages(stats)
click to toggle source
# File lib/big_3/league.rb, line 87 def find_season_averages(stats) stats["season"].each do |k, v| average = v / stats["games"].length stats["season"][k] = average.round(2).to_s end end
names_match?(item, passed_item)
click to toggle source
# File lib/big_3/league.rb, line 106 def names_match?(item, passed_item) item["@name"].gsub(/[^A-Za-z]/, "").downcase == passed_item.gsub(/[^A-Za-z]/, "").downcase end
parse_game_stats(players, stats, location)
click to toggle source
# File lib/big_3/league.rb, line 50 def parse_game_stats(players, stats, location) players.each do |player| if names_match?(player, player_name) stats["games"] << { "stats" => player["stats"], "location" => location, "game_number" => "#{stats["games"].length + 1}" } player["stats"].each do |k, v| v = v.to_f stats["season"][k] += v end else next end end end
retrieve_game_data()
click to toggle source
# File lib/big_3/league.rb, line 155 def retrieve_game_data @game_stats = GameManager.new({ids: game_ids}).create_games @game_stats end
rosters()
click to toggle source
# File lib/big_3/league.rb, line 165 def rosters @rosters ||= find_rosters end
team_stats()
click to toggle source
# File lib/big_3/league.rb, line 15 def team_stats @t_s = Hash.new { |h, k| h[k] = [] } @t_s["season"] = Hash.new { |h, k| h[k] = 0 } game_stats.each.with_index(1) do |teams, game_count| scores = {} if team_name.nil? add_scoring(scores, teams.away_team, teams.home_team) add_stats(scores, teams.away_team, teams.home_team, t_s, teams.location, game_count) else filter_team_stats(scores, teams.away_team, teams.home_team, t_s, teams.away_team, teams.location, game_count) end end unless team_name.nil? find_season_averages(t_s) else @t_s.delete("season") end @t_s end
teams()
click to toggle source
# File lib/big_3/league.rb, line 160 def teams @teams = ["Tri State", "Killer 3s", "Ball Hogs", "3 Headed Monsters", "Trilogy", "Power", "Ghost Ballers", "3's Company"] @teams end