class AhlScraper::Games::ShootoutStatlinesService

Public Class Methods

new(shootout_data, team_id, skater_ids) click to toggle source
# File lib/ahl_scraper/services/games/shootout_statlines_service.rb, line 6
def initialize(shootout_data, team_id, skater_ids)
  @shootout_data = shootout_data
  @team_id = team_id
  @skater_ids = skater_ids
end

Public Instance Methods

call() click to toggle source
# File lib/ahl_scraper/services/games/shootout_statlines_service.rb, line 12
def call
  return {} unless @shootout_data

  @shootout_data.each do |shootout_attempt|
    skater_id = shootout_attempt[:shooter][:id].to_s
    shootout_statlines[skater_id] ||= blank_statline

    shootout_statlines[skater_id][:attempts] += 1
    shootout_statlines[skater_id][:goals] += 1 if shootout_attempt[:isGoal]
    shootout_statlines[skater_id][:game_winners] += 1 if shootout_attempt[:isGameWinningGoal]
  end

  shootout_statlines
end

Private Instance Methods

blank_statline() click to toggle source
# File lib/ahl_scraper/services/games/shootout_statlines_service.rb, line 33
def blank_statline
  {
    attempts: 0,
    goals: 0,
    game_winners: 0,
  }
end
shootout_statlines() click to toggle source
# File lib/ahl_scraper/services/games/shootout_statlines_service.rb, line 29
def shootout_statlines
  @shootout_statlines ||= @skater_ids.map { |s_id| [s_id.to_s, blank_statline] }.to_h
end