Class: Sportradar::Nfl::PlaySummaries

Inherits:
PlayByPlay show all
Defined in:
lib/sportradar/nfl/play_summaries.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PlayByPlay

#path

Methods inherited from GameRequest

#game_path, #initialize

Methods inherited from WeeklySchedule

#initialize, #path, #week_path

Methods inherited from LeagueSchedule

#fetch, games, #path

Methods inherited from Feeds::LeagueSchedule

#initialize, #path

Methods inherited from ApiRequest

#client, #endpoint, fetch, #fetch, #league, #path, save, #save

Constructor Details

This class inherits a constructor from Sportradar::Nfl::GameRequest

Class Method Details

.perform(year: nil, interval_type: nil, week: 1, away_team_abbreviation:, home_team_abbreviation:) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/sportradar/nfl/play_summaries.rb', line 4

def self.perform(year: nil,
                 interval_type: nil,
                 week: 1,
                 away_team_abbreviation:,
                 home_team_abbreviation:)
  new(year: year,
      interval_type: interval_type,
      week: week,
      away_team_abbreviation: away_team_abbreviation,
      home_team_abbreviation: home_team_abbreviation).perform
end

Instance Method Details

#performObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sportradar/nfl/play_summaries.rb', line 16

def perform
  (quarters || []).each do |quarter|
    (quarter['pbp'] || []).each do |pbp|
      (pbp['actions'] || []).each do |action|
        next unless action['type'] == 'play'

        PlaySummary.new(week: @week,
                        year: @year,
                        interval_type: @interval_type,
                        away_team_abbreviation: @away_team_abbreviation,
                        home_team_abbreviation: @home_team_abbreviation,
                        play_id: action['id']).save
      end
    end
  end

  nil
end