Class: Sportradar::Api::Baseball::Inning
- Defined in:
- lib/sportradar/api/baseball/inning.rb
Instance Attribute Summary collapse
-
#game ⇒ Object
Returns the value of attribute game.
-
#id ⇒ Object
Returns the value of attribute id.
-
#number ⇒ Object
Returns the value of attribute number.
-
#response ⇒ Object
Returns the value of attribute response.
-
#scoring ⇒ Object
Returns the value of attribute scoring.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
Instance Method Summary collapse
- #events ⇒ Object
- #half_innings ⇒ Object
-
#initialize(data, **opts) ⇒ Inning
constructor
A new instance of Inning.
- #parse_scoring(data) ⇒ Object
- #update(data, **opts) ⇒ Object
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
#game ⇒ Object
Returns the value of attribute game.
5 6 7 |
# File 'lib/sportradar/api/baseball/inning.rb', line 5 def game @game end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/baseball/inning.rb', line 5 def id @id end |
#number ⇒ Object
Returns the value of attribute number.
5 6 7 |
# File 'lib/sportradar/api/baseball/inning.rb', line 5 def number @number end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/sportradar/api/baseball/inning.rb', line 5 def response @response end |
#scoring ⇒ Object
Returns the value of attribute scoring.
5 6 7 |
# File 'lib/sportradar/api/baseball/inning.rb', line 5 def scoring @scoring end |
#sequence ⇒ Object
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
#events ⇒ Object
35 36 37 |
# File 'lib/sportradar/api/baseball/inning.rb', line 35 def events half_innings.flat_map(&:events) end |
#half_innings ⇒ Object
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 |