Class: SportsDataApi::Nfl::Game
- Inherits:
-
Object
- Object
- SportsDataApi::Nfl::Game
- Defined in:
- lib/sports_data_api/nfl/game.rb
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#quarter ⇒ Object
readonly
Returns the value of attribute quarter.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #away_team ⇒ Object
- #away_team_id ⇒ Object
- #broadcast ⇒ Object
- #home_team ⇒ Object
- #home_team_id ⇒ Object
-
#initialize(json, year: nil, season: nil, week: nil) ⇒ Game
constructor
A new instance of Game.
- #scheduled ⇒ Object
- #season ⇒ Object
- #venue ⇒ Object
- #week ⇒ Object
- #year ⇒ Object
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
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
4 5 6 |
# File 'lib/sports_data_api/nfl/game.rb', line 4 def clock @clock end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/sports_data_api/nfl/game.rb', line 4 def id @id end |
#quarter ⇒ Object (readonly)
Returns the value of attribute quarter.
4 5 6 |
# File 'lib/sports_data_api/nfl/game.rb', line 4 def quarter @quarter end |
#status ⇒ Object (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_team ⇒ Object
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_id ⇒ Object
38 39 40 |
# File 'lib/sports_data_api/nfl/game.rb', line 38 def away_team_id dig_key('away', 'summary')['id'] end |
#broadcast ⇒ Object
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_team ⇒ Object
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_id ⇒ Object
34 35 36 |
# File 'lib/sports_data_api/nfl/game.rb', line 34 def home_team_id dig_key('home', 'summary')['id'] end |
#scheduled ⇒ Object
30 31 32 |
# File 'lib/sports_data_api/nfl/game.rb', line 30 def scheduled Time.parse(json['scheduled']) end |
#season ⇒ Object
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 |
#venue ⇒ Object
56 57 58 |
# File 'lib/sports_data_api/nfl/game.rb', line 56 def venue Venue.new(dig_key('venue', 'summary')) end |
#week ⇒ Object
26 27 28 |
# File 'lib/sports_data_api/nfl/game.rb', line 26 def week @week || json.fetch('summary', {}).fetch('week', {})['sequence'] end |
#year ⇒ Object
18 19 20 |
# File 'lib/sports_data_api/nfl/game.rb', line 18 def year @year || json.fetch('summary', {}).fetch('season', {})['year'] end |