Sha256: 258dd1ed2c66f0b070be31c02ead7d4cc2d46f6bc2689aff17ce1d2bfc331c10

Contents?: true

Size: 1.1 KB

Versions: 170

Compression:

Stored size: 1.1 KB

Contents

module Sportradar
  module Api
    module Baseball
      class Inning < Data
        attr_accessor :response, :id, :game, :number, :sequence, :scoring

        def initialize(data, **opts)
          @response = data
          @api      = opts[:api]
          @game     = opts[:game]

          @id       = data["id"]
          @number   = data['number']
          @sequence = data['sequence']

          parse_scoring(data['scoring']) if data['scoring']

          @half_innings_hash = {}

          update(data)
        end
        def update(data, **opts)
          # update scoring
          halfs = data['halfs'].each { |inning| inning['id'] = "#{data['id']}-#{inning['half']}" }
          create_data(@half_innings_hash, halfs, klass: HalfInning, api: @api, inning: self)
        end
        def parse_scoring(data)
          @scoring = data.each_with_object({}) { |(_, data), hash| hash[data['id']] = data['runs'].to_s } # from PBP
        end

        def half_innings
          @half_innings_hash.values
        end

        def events
          half_innings.flat_map(&:events)
        end

      end
    end
  end
end

Version data entries

170 entries across 170 versions & 1 rubygems

Version Path
sportradar-api-0.11.28 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.27 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.26 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.25 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.24 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.23 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.22 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.21 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.20 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.19 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.18 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.17 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.16 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.15 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.14 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.13 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.12 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.11 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.10 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.9 lib/sportradar/api/baseball/inning.rb