Class: SportsDataApi::Nfl::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_data_api/nfl/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, year: nil, season: nil, week: nil) ⇒ Game

Returns a new instance of Game.



6
7
8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#clockObject (readonly)

Returns the value of attribute clock.



4
5
6
# File 'lib/sports_data_api/nfl/game.rb', line 4

def clock
  @clock
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/sports_data_api/nfl/game.rb', line 4

def id
  @id
end

#quarterObject (readonly)

Returns the value of attribute quarter.



4
5
6
# File 'lib/sports_data_api/nfl/game.rb', line 4

def quarter
  @quarter
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/sports_data_api/nfl/game.rb', line 4

def status
  @status
end

Instance Method Details

#away_teamObject



49
50
51
52
53
54
# 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_idObject



38
39
40
# File 'lib/sports_data_api/nfl/game.rb', line 38

def away_team_id
  dig_key('away', 'summary')['id']
end

#broadcastObject



60
61
62
63
# File 'lib/sports_data_api/nfl/game.rb', line 60

def broadcast
  return unless json['broadcast']
  Broadcast.new(json['broadcast'])
end

#home_teamObject



42
43
44
45
46
47
# 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_idObject



34
35
36
# File 'lib/sports_data_api/nfl/game.rb', line 34

def home_team_id
  dig_key('home', 'summary')['id']
end

#scheduledObject



30
31
32
# File 'lib/sports_data_api/nfl/game.rb', line 30

def scheduled
  Time.parse(json['scheduled'])
end

#seasonObject



22
23
24
# File 'lib/sports_data_api/nfl/game.rb', line 22

def season
  @season || json.fetch('summary', {}).fetch('season', {})['name']&.to_sym
end

#venueObject



56
57
58
# File 'lib/sports_data_api/nfl/game.rb', line 56

def venue
  Venue.new(dig_key('venue', 'summary'))
end

#weekObject



26
27
28
# File 'lib/sports_data_api/nfl/game.rb', line 26

def week
  @week || json.fetch('summary', {}).fetch('week', {})['sequence']
end

#yearObject



18
19
20
# File 'lib/sports_data_api/nfl/game.rb', line 18

def year
  @year || json.fetch('summary', {}).fetch('season', {})['year']
end