Class: Sportradar::Nhl::Parsers::PlayByPlayParser

Inherits:
Object
  • Object
show all
Defined in:
lib/sportradar/nhl/parsers/play_by_play_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(game_play_by_play: {}) ⇒ PlayByPlayParser

Returns a new instance of PlayByPlayParser.



5
6
7
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 5

def initialize(game_play_by_play: {})
  @game_play_by_play = game_play_by_play['game'] || game_play_by_play
end

Instance Method Details

#awayObject



13
14
15
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 13

def away
  game_play_by_play['away'] || {}
end

#away_team_idObject



17
18
19
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 17

def away_team_id
  away['id']
end

#eventsObject



33
34
35
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 33

def events
  (periods || []).map(&:events).flatten
end

#game_idObject



9
10
11
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 9

def game_id
  game_play_by_play['id']
end

#has_periods?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 29

def has_periods?
  periods.count > 0
end

#homeObject



21
22
23
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 21

def home
  game_play_by_play['home'] || {}
end

#penaltiesObject



37
38
39
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 37

def penalties
  (periods || []).map(&:penalties).flatten
end

#periodsObject



25
26
27
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 25

def periods
  @periods ||= build_periods || []
end

#playsObject



41
42
43
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 41

def plays
  (periods || []).map(&:plays).flatten
end

#scoring_playsObject



45
46
47
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 45

def scoring_plays
  (periods || []).map(&:scoring_plays).flatten
end

#stoppagesObject



49
50
51
# File 'lib/sportradar/nhl/parsers/play_by_play_parser.rb', line 49

def stoppages
  (periods || []).map(&:stoppages).flatten
end