lib/sportradar/api/nfl/game.rb in sportradar-api-0.9.14 vs lib/sportradar/api/nfl/game.rb in sportradar-api-0.9.15
- old
+ new
@@ -80,10 +80,23 @@
def current_score
"#{summary.home.points}-#{summary.away.points}" if summary
end
def drives
- Array(quarters&.flat_map(&:drives)).compact
+ @drives ||= begin
+ drives = Array(quarters&.flat_map(&:drives)).compact
+ # Scan for duplicates
+ drives.each_cons(2) do |a,b|
+ # Merge plays and events into the first if duplicate and flag dup for removal
+ if a.id == b.id
+ a.plays.concat(b.plays)
+ Array(a.events).concat(Array(b.events)).uniq!
+ b.id = nil
+ end
+ end
+ # Remove the dup
+ drives.delete_if{ |d| d.id.nil? }
+ end
end
def plays
Array(drives&.flat_map(&:plays)).compact
end