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.28 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.27 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.26 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.25 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.24 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.23 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.22 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.21 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.20 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.19 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.18 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.17 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.16 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.15 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.14 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.13 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.12 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.11 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.10 lib/sportradar/api/baseball/event.rb
sportradar-api-0.11.9 lib/sportradar/api/baseball/event.rb