Class: Sportradar::Api::Baseball::HalfInning

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/baseball/half_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) ⇒ HalfInning

Returns a new instance of HalfInning.



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

def initialize(data, **opts)
  @response = data
  @api      = opts[:api]
  @inning   = opts[:inning]
  @id       = data["id"]
  *@inning_id, @number, @half = data['id'].split('-')

  @events_hash = {}

  update(data)

end

Instance Attribute Details

#halfObject

Returns the value of attribute half.



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

def half
  @half
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#inningObject

Returns the value of attribute inning.



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

def inning
  @inning
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#at_batsObject



34
35
36
# File 'lib/sportradar/api/baseball/half_inning.rb', line 34

def at_bats
  events.map(&:at_bat).compact
end

#error_countObject



59
60
61
# File 'lib/sportradar/api/baseball/half_inning.rb', line 59

def error_count
  errors.count
end

#errorsObject



55
56
57
# File 'lib/sportradar/api/baseball/half_inning.rb', line 55

def errors
  at_bats.flat_map(&:pitches).flat_map(&:errors).compact
end

#eventsObject



42
43
44
45
# File 'lib/sportradar/api/baseball/half_inning.rb', line 42

def events
  # @events_hash.values
  @events
end

#hit_countObject



51
52
53
# File 'lib/sportradar/api/baseball/half_inning.rb', line 51

def hit_count
  hits.count
end

#hitsObject



47
48
49
# File 'lib/sportradar/api/baseball/half_inning.rb', line 47

def hits
  at_bats.flat_map(&:pitches).select {|pitch| pitch.is_hit }
end

#lineup_changesObject



38
39
40
# File 'lib/sportradar/api/baseball/half_inning.rb', line 38

def lineup_changes
  # events_by_klass(LineupChange)
end

#over?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sportradar/api/baseball/half_inning.rb', line 26

def over?
  pitches.last&.count&.dig('outs') == 3
end

#pitchesObject



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

def pitches
  at_bats.flat_map(&:pitches)
end

#update(data, **opts) ⇒ Object



20
21
22
23
24
# File 'lib/sportradar/api/baseball/half_inning.rb', line 20

def update(data, **opts)
  @half     = data['half']
  @events   = data['events'].map{ |hash| Event.new(hash, half_inning: self) }
  # create_data(@events_hash, data['events'], klass: Event, api: @api, half_inning: self)
end