lib/sportradar/api/nfl/game.rb in sportradar-api-0.1.38 vs lib/sportradar/api/nfl/game.rb in sportradar-api-0.9.0
- old
+ new
@@ -19,52 +19,52 @@
@number = data["number"]
@attendance = data["attendance"]
@utc_offset = data["utc_offset"]
@weather = data["weather"]
@clock = data["clock"]
+
if data["quarter"]
@quarter = data["quarter"][0]
quarter_data = data["quarter"][1].is_a?(Hash) ? [ data["quarter"][1] ] : data["quarter"][1]
@quarters = quarter_data&.map { |hash| Sportradar::Api::Nfl::Quarter.new(hash) }
end
+
@summary = Sportradar::Api::Nfl::Summary.new data["summary"] if data["summary"]
@situation = Sportradar::Api::Nfl::Situation.new data["situation"] if data["situation"]
@last_event = Sportradar::Api::Nfl::Event.new data["last_event"]["event"] if data["last_event"] && data["last_event"]["event"]
@scoring = Sportradar::Api::Nfl::Scoring.new data["scoring"] if data["scoring"]
- set_scoring_drives
+ @scoring_drives = parse_into_array(selector: response["scoring_drives"]["drive"], klass: Sportradar::Api::Nfl::Drive) if response["scoring_drives"] && response["scoring_drives"]["drive"]
+
location = data["summary"] || data
@venue = Sportradar::Api::Nfl::Venue.new data["venue"] || location["venue"] if data["venue"] || location["venue"]
@home = Sportradar::Api::Nfl::Team.new data["home"] || location["home"] if data["home"] || location["home"]
@away = Sportradar::Api::Nfl::Team.new data["away"] || location["away"] if data["away"] || location["away"]
+
@broadcast = Sportradar::Api::Nfl::Broadcast.new data["broadcast"] if data["broadcast"]
+
if data["team"]
- @stats = data["team"].map { |hash| [hash["id"], Sportradar::Api::Nfl::GameStatistic.new(hash)] }.to_h
+ @stats = data["team"].map { |team_stat| [team_stat["id"], Sportradar::Api::Nfl::GameStatistic.new(team_stat)] }.to_h
@home.stats = @stats[@home.id]
@away.stats = @stats[@away.id]
end
+
end
+ def sport_league
+ 'NFL'.freeze
+ end
+
def current_score
"#{summary.home.points}-#{summary.away.points}" if summary
end
+
def drives
quarters&.flat_map(&:drives)
end
+
def plays
drives&.flat_map(&:plays)
- end
-
- private
-
- def set_scoring_drives
- if response["scoring_drives"] && response["scoring_drives"]["drive"]
- if response["scoring_drives"]["drive"].is_a?(Array)
- @scoring_drives = response["scoring_drives"]["drive"].map {|scoring_drive| Sportradar::Api::Nfl::Drive.new scoring_drive }
- elsif response["scoring_drives"]["drive"].is_a?(Hash)
- @scoring_drives = [ Sportradar::Api::Nfl::Drive.new(response["scoring_drives"]["drive"]) ]
- end
- end
end
end
end
end