Class: AhlScraper::Games::CreateSkatersService

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

Instance Method Summary collapse

Constructor Details

#initialize(skater_data, goal_data, penalty_data, shootout_data, penalty_shot_data, opts = {}) ⇒ CreateSkatersService

Returns a new instance of CreateSkatersService.



6
7
8
9
10
11
12
13
# File 'lib/ahl_scraper/services/games/create_skaters_service.rb', line 6

def initialize(skater_data, goal_data, penalty_data, shootout_data, penalty_shot_data, opts = {})
  @skater_data = skater_data
  @goal_data = goal_data
  @penalty_data = penalty_data
  @shootout_data = shootout_data
  @penalty_shot_data = penalty_shot_data
  @opts = opts
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ahl_scraper/services/games/create_skaters_service.rb', line 15

def call
  scoring_statlines = ScoringStatlinesService.new(team_goals, skater_ids, @opts).call
  on_ice_statlines = OnIceStatlinesService.new(@goal_data, @opts[:team_id], skater_ids).call
  penalty_statlines = PenaltyStatlinesService.new(@penalty_data, @opts[:team_id], skater_ids).call
  penalty_shot_statlines = PenaltyShotStatlinesService.new(@penalty_shot_data, @opts[:team_id], skater_ids).call
  shootout_statlines = ShootoutStatlinesService.new(@shootout_data, @opts[:team_id], skater_ids).call

  skaters.map do |s|
    id_key = s[:id].to_s
    Skater.new(
      s,
      {
        **@opts,
        scoring_statline: scoring_statlines[id_key],
        on_ice_statline: on_ice_statlines[id_key],
        penalty_statline: penalty_statlines[id_key],
        penalty_shot_statline: penalty_shot_statlines[id_key],
        shootout_statline: shootout_statlines[id_key],
      }
    )
  end
end