class Sportradar::Nhl::Models::Period

Public Class Methods

new(game_id:, attributes:) click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 5
def initialize(game_id:, attributes:)
  @game_id = game_id
  @attributes = attributes
  build_events
end

Public Instance Methods

abbreviation() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 15
def abbreviation
  case type
  when 'period'
    "#{number}P"
  when 'overtime'
    "#{number}OT"
  when 'shootout'
    'SO'
  else
    "#{number}"
  end
end
events() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 48
def events
  @events ||= []
end
events_data() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 52
def events_data
  @actions ||= @attributes.dig('events') || []
end
game_id() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 28
def game_id
  @game_id
end
id() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 32
def id
  @id
end
number() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 36
def number
  @attributes['number'] || 0
end
penalties() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 56
def penalties
  @penalties ||= []
end
plays() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 60
def plays
  @plays ||= []
end
scoring_plays() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 64
def scoring_plays
  @scoring_plays ||= []
end
sequence() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 40
def sequence
  @attributes['sequence'] || 0
end
stoppages() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 68
def stoppages
  @stoppages ||= []
end
to_s() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 11
def to_s
  "#{type.titleize} #{number}"
end
type() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 44
def type
  @attributes['type']
end

Private Instance Methods

build_events() click to toggle source
# File lib/sportradar/nhl/models/period.rb, line 74
def build_events
  events_data.each do |event_data|
    event = Models::Event.new(period: self, attributes: event_data)
    events << event
    plays << event if event.play?
    stoppages << event if event.stoppage?
    penalties << Models::Penalty.new(period: self, attributes: event_data) if event.penalty?
    scoring_plays << Models::ScoringPlay.new(period: self, attributes: event_data) if event.scoring_play?
  end
end