class AhlScraper::Games::PenaltyShotStatlinesService

Public Class Methods

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

Public Instance Methods

call() click to toggle source
# File lib/ahl_scraper/services/games/penalty_shot_statlines_service.rb, line 12
def call
  @penalty_shot_data.each do |penalty_shot|
    skater_id = penalty_shot[:shooter][:id].to_s
    penalty_shot_statlines[skater_id] ||= blank_statline

    penalty_shot_statlines[skater_id][:attempts] += 1
    penalty_shot_statlines[skater_id][:goals] += 1 if penalty_shot[:isGoal]
  end

  penalty_shot_statlines
end

Private Instance Methods

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