Class: Sportradar::Api::Baseball::Event

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/baseball/event.rb,
lib/sportradar/api/baseball/events/at_bat.rb,
lib/sportradar/api/baseball/events/lineup.rb,
lib/sportradar/api/baseball/events/warming_up.rb

Defined Under Namespace

Classes: AtBat, Lineup, WarmingUp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(hash, **opts) ⇒ Event

alias :type :event_type



8
9
10
11
12
13
14
# File 'lib/sportradar/api/baseball/event.rb', line 8

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

Instance Attribute Details

#at_batObject

Returns the value of attribute at_bat.



5
6
7
# File 'lib/sportradar/api/baseball/event.rb', line 5

def at_bat
  @at_bat
end

#half_inningObject

Returns the value of attribute half_inning.



5
6
7
# File 'lib/sportradar/api/baseball/event.rb', line 5

def half_inning
  @half_inning
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/baseball/event.rb', line 5

def id
  @id
end

#lineupObject

Returns the value of attribute lineup.



5
6
7
# File 'lib/sportradar/api/baseball/event.rb', line 5

def lineup
  @lineup
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/baseball/event.rb', line 5

def response
  @response
end

#warming_upObject

Returns the value of attribute warming_up.



5
6
7
# File 'lib/sportradar/api/baseball/event.rb', line 5

def warming_up
  @warming_up
end

Class Method Details

.subclass(event_type) ⇒ Object

def ==(other)

@at_bat == other.at_bat && @warming_up == other.warming_up && @lineup == other.lineup

end



30
31
32
# File 'lib/sportradar/api/baseball/event.rb', line 30

def self.subclass(event_type)
  subclasses[event_type]
end

.subclassesObject



33
34
35
36
37
38
39
# File 'lib/sportradar/api/baseball/event.rb', line 33

def self.subclasses
  @subclasses ||= {
    'at_bat'      => AtBat,
    'lineup'      => Lineup,
    'warming_up'  => WarmingUp,
  }.freeze
end

Instance Method Details

#descriptionObject



16
17
18
# File 'lib/sportradar/api/baseball/event.rb', line 16

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