Sha256: ee01b1cdcb8536a3b6d3f154c594098d92dd166a9165deabeedd37706c0c8a1b

Contents?: true

Size: 1.2 KB

Versions: 30

Compression:

Stored size: 1.2 KB

Contents

module Sportradar
  module Api
    module Baseball
      class HalfInning < Data
        attr_accessor :response, :id, :inning, :type, :half, :number

        def initialize(data, **opts)
          @response = data
          @api      = opts[:api]
          @inning   = opts[:inning]
          @id       = data["id"]
          *@inning_id, @number, @half = data['id'].split('-')

          @events_hash = {}

          update(data)

        end

        def update(data, **opts)
          @half     = data['half']
          @events   = data['events'].map{ |hash| Event.new(hash, half_inning: self) }
          # create_data(@events_hash, data['events'], klass: Event, api: @api, half_inning: self)
        end

        def over?
          pitches.last.count&.dig('outs') == 3
        end

        def pitches
          at_bats.flat_map(&:pitches)
        end

        def at_bats
          events.map(&:at_bat).compact
        end

        def lineup_changes
          # events_by_klass(LineupChange)
        end

        def events
          # @events_hash.values
          @events
        end

        # private def events_by_klass(klass)
        #   @events_hash.each_value.grep(klass)
        # end

      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
sportradar-api-0.10.43 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.42 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.41 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.40 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.39 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.38 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.37 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.36 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.35 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.34 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.33 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.32 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.31 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.30 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.29 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.28 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.27 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.26 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.25 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.10.24 lib/sportradar/api/baseball/half_inning.rb