Class: Sportradar::Api::Baseball::Inning

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/baseball/inning.rb

Instance Attribute 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(data, **opts) ⇒ Inning

Returns a new instance of Inning.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sportradar/api/baseball/inning.rb', line 7

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]
  @game     = opts[:game]

  @id       = data["id"]
  @number   = data['number']
  @sequence = data['sequence']

  parse_scoring(data['scoring']) if data['scoring']

  @half_innings_hash = {}

  update(data)
end

Instance Attribute Details

#gameObject

Returns the value of attribute game.



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

def game
  @game
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#scoringObject

Returns the value of attribute scoring.



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

def scoring
  @scoring
end

#sequenceObject

Returns the value of attribute sequence.



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

def sequence
  @sequence
end

Instance Method Details

#eventsObject



35
36
37
# File 'lib/sportradar/api/baseball/inning.rb', line 35

def events
  half_innings.flat_map(&:events)
end

#half_inningsObject



31
32
33
# File 'lib/sportradar/api/baseball/inning.rb', line 31

def half_innings
  @half_innings_hash.values
end

#parse_scoring(data) ⇒ Object



27
28
29
# File 'lib/sportradar/api/baseball/inning.rb', line 27

def parse_scoring(data)
  @scoring = data.each_with_object({}) { |(_, data), hash| hash[data['id']] = data['runs'].to_s } # from PBP
end

#update(data, **opts) ⇒ Object



22
23
24
25
26
# File 'lib/sportradar/api/baseball/inning.rb', line 22

def update(data, **opts)
  # update scoring
  halfs = data['halfs'].each { |inning| inning['id'] = "#{data['id']}-#{inning['half']}" }
  create_data(@half_innings_hash, halfs, klass: HalfInning, api: @api, inning: self)
end