class SportsDataApi::Nfl::Game

Attributes

clock[R]
id[R]
json[R]
quarter[R]
status[R]

Public Class Methods

new(json, year: nil, season: nil, week: nil) click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 6
def initialize(json, year: nil, season: nil, week: nil)
  @json = json
  @year = year
  @season = season
  @week = week

  @id = json['id']
  @status = json['status']
  @quarter = json['quarter']&.to_i
  @clock = json['clock']
end

Public Instance Methods

away_team() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 49
def away_team
  Team.new(
    dig_key('away', 'summary'),
    statistics: json.fetch('statistics', {})['away']
  )
end
away_team_id() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 38
def away_team_id
  dig_key('away', 'summary')['id']
end
broadcast() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 60
def broadcast
  return unless json['broadcast']
  Broadcast.new(json['broadcast'])
end
home_team() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 42
def home_team
  Team.new(
    dig_key('home', 'summary'),
    statistics: json.fetch('statistics', {})['home']
  )
end
home_team_id() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 34
def home_team_id
  dig_key('home', 'summary')['id']
end
scheduled() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 30
def scheduled
  Time.parse(json['scheduled'])
end
season() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 22
def season
  @season || json.fetch('summary', {}).fetch('season', {})['name']&.to_sym
end
venue() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 56
def venue
  Venue.new(dig_key('venue', 'summary'))
end
week() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 26
def week
  @week || json.fetch('summary', {}).fetch('week', {})['sequence']
end
year() click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 18
def year
  @year || json.fetch('summary', {}).fetch('season', {})['year']
end

Private Instance Methods

dig_key(key, secondary) click to toggle source
# File lib/sports_data_api/nfl/game.rb, line 69
def dig_key(key, secondary)
  json[key] || json.fetch(secondary, {})[key]
end