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.20.2 lib/sportradar/api/baseball/event.rb
sportradar-api-0.20.1 lib/sportradar/api/baseball/event.rb
sportradar-api-0.20.0 lib/sportradar/api/baseball/event.rb
sportradar-api-0.20.0.pre2 lib/sportradar/api/baseball/event.rb
sportradar-api-0.20.0.pre lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.6 lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.5 lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.4 lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.3 lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.2 lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.1 lib/sportradar/api/baseball/event.rb
sportradar-api-0.19.0 lib/sportradar/api/baseball/event.rb
sportradar-api-0.18.1 lib/sportradar/api/baseball/event.rb
sportradar-api-0.18.0 lib/sportradar/api/baseball/event.rb
sportradar-api-0.17.6 lib/sportradar/api/baseball/event.rb
sportradar-api-0.17.5 lib/sportradar/api/baseball/event.rb
sportradar-api-0.17.5.pre lib/sportradar/api/baseball/event.rb
sportradar-api-0.17.4 lib/sportradar/api/baseball/event.rb
sportradar-api-0.17.3 lib/sportradar/api/baseball/event.rb
sportradar-api-0.17.2 lib/sportradar/api/baseball/event.rb