Sha256: fc865693de4f9dd19f4fbd0cd5ec4529e8569be89789239a1268deaf8fa2f084

Contents?: true

Size: 1.51 KB

Versions: 135

Compression:

Stored size: 1.51 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

        def hits
          at_bats.flat_map(&:pitches).select {|pitch| pitch.is_hit }
        end

        def hit_count
          hits.count
        end

        def errors
          at_bats.flat_map(&:pitches).flat_map(&:errors).compact
        end

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

      end
    end
  end
end

Version data entries

135 entries across 135 versions & 1 rubygems

Version Path
sportradar-api-0.11.48 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.47 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.46 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.45 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.44 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.43 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.42 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.41 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.40 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.39 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.38 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.37 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.36 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.35 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.34 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.33 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.32 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.31 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.30 lib/sportradar/api/baseball/half_inning.rb
sportradar-api-0.11.29 lib/sportradar/api/baseball/half_inning.rb