Class: AhlScraper::Games::PenaltyStatlinesService

Inherits:
Object
  • Object
show all
Defined in:
lib/ahl_scraper/services/games/penalty_statlines_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(penalty_data, team_id, skater_ids) ⇒ PenaltyStatlinesService

Returns a new instance of PenaltyStatlinesService.



6
7
8
9
10
# 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

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# 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