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.17.1 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.17.0 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.17.0.pre lib/sportradar/api/baseball/inning.rb
sportradar-api-0.16.1 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.16.0 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.15.1 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.15.0 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.14.0 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.26 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.25 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.24 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.23 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.22 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.21 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.20 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.19 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.18 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.17 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.16 lib/sportradar/api/baseball/inning.rb
sportradar-api-0.13.15 lib/sportradar/api/baseball/inning.rb