class AhlScraper::Games::PenaltyStatlinesService

Public Class Methods

new(penalty_data, team_id, skater_ids) click to toggle source
# File lib/ahl_scraper/services/games/penalty_statlines_service.rb, line 6
def initialize(penalty_data, team_id, skater_ids)
  @penalty_data = penalty_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_statlines_service.rb, line 12
def call
  @penalty_data.each do |penalty|
    next unless penalty[:takenBy]

    skater_id = penalty_statlines[penalty[:takenBy][:id].to_s] ? penalty[:takenBy][:id].to_s : false
    next unless skater_id

    penalty_statlines[skater_id][penalty_type(penalty)] += 1
    penalty_statlines[skater_id][:penalty_minutes] += penalty[:minutes].to_i
  end

  penalty_statlines
end

Private Instance Methods

blank_statline() click to toggle source
# File lib/ahl_scraper/services/games/penalty_statlines_service.rb, line 32
def blank_statline
  {
    penalty_minutes: 0,
    minors: 0,
    double_minors: 0,
    majors: 0,
    fights: 0,
    misconducts: 0,
    game_misconducts: 0,
  }
end
penalty_statlines() click to toggle source
# File lib/ahl_scraper/services/games/penalty_statlines_service.rb, line 28
def penalty_statlines
  @penalty_statlines ||= @skater_ids.map { |s_id| [s_id.to_s, blank_statline] }.to_h
end
penalty_type(penalty) click to toggle source
# File lib/ahl_scraper/services/games/penalty_statlines_service.rb, line 44
def penalty_type(penalty)
  case penalty[:description]
  when /double minor/i
    :double_minors
  when /major/i
    :majors
  when /fighting/i
    :fights
  when /game misconduct/i
    :game_misconducts
  when /misconduct/i
    :misconducts
  else
    :minors
  end
end