Sha256: 9dc0fdb7b10692ac7b23a5ab18be84df37f27608129b56e7c326522af1b1e69c

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

module Sportradar
  module Api
    module Baseball
      class Event
        class AtBat < Data
          attr_accessor :response, :id, :event, :hitter_id, :outcome, :description

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

            @id       = data["id"]
            @type     = data['type']

            @pitches_hash = {}

            update(data)
          end

          # def ==(other)
          #   return false if other.nil?
          #   @id == other.id && pitches == other.pitches
          # end

          def update(data, **opts)
            @description  = data['description'] if data['description']
            @hitter_id    = data['hitter_id']   if data['hitter_id']
            # this hasn't been checked yet
            # pitch events
            create_data(@pitches_hash, data.dig('events'), klass: Pitch, api: @api, at_bat: self)
          end

          def data_key
            'at_bat'
          end

          def over?
            pitches.last.is_ab_over
          end

          def pitches
            @pitches_hash.values
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sportradar-api-0.10.28 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.27 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.26 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.25 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.24 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.23 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.22 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.21 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.20 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.19 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.18 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.17 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.16 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.15 lib/sportradar/api/baseball/events/at_bat.rb
sportradar-api-0.10.14 lib/sportradar/api/baseball/events/at_bat.rb