Sha256: aae42008cd506312af6c193444ab8027a3bdb9dfafaeb99ce9ade65b1c284478

Contents?: true

Size: 1.28 KB

Versions: 170

Compression:

Stored size: 1.28 KB

Contents

module Sportradar
  module Api
    module Baseball
      class Event < Data
        attr_accessor :response, :id, :at_bat, :lineup, :warming_up, :half_inning
        # alias :type :event_type

        def initialize(hash, **opts)
          @response = hash
          @half_inning = opts[:half_inning]
          @at_bat     = AtBat.new(hash['at_bat'],         event: self) if hash['at_bat']
          @lineup     = Lineup.new(hash['lineup'],        event: self) if hash['lineup']
          @warming_up = WarmingUp.new(hash['warming_up'], event: self) if hash['warming_up']
        end

        def description
          (@at_bat || @lineup || @warming_up)&.description
        end

        # def self.new(data, **opts)
        #   klass = subclass(data.keys.first)
        #   klass.new(data, **opts)
        # rescue => e
        #   binding.pry
        # end

        # def ==(other)
        #   @at_bat == other.at_bat && @warming_up == other.warming_up && @lineup == other.lineup
        # end
        def self.subclass(event_type)
          subclasses[event_type]
        end
        def self.subclasses
          @subclasses ||= {
            'at_bat'      => AtBat,
            'lineup'      => Lineup,
            'warming_up'  => WarmingUp,
          }.freeze
        end

      end
    end
  end
end

Version data entries

170 entries across 170 versions & 1 rubygems

Version Path
sportradar-api-0.11.68 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.67 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.66 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.65 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.64 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.63 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.62 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.61 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.60 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.59 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.58 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.57 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.56 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.55 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.54 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.53 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.52 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.51 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.50 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.49 lib/sportradar/api/baseball/event.rb