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.48 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.47 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.46 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.45 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.44 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.43 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.42 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.41 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.40 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.39 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.38 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.37 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.36 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.35 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.34 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.33 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.32 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.31 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.30 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.11.29 lib/sportradar/api/baseball/inning.rb