Class: Sportradar::Api::Baseball::HalfInning
- Inherits:
-
Data
- Object
- Data
- Sportradar::Api::Baseball::HalfInning
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
#half ⇒ Object
Returns the value of attribute half.
5
6
7
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 5
def half
@half
end
|
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 5
def id
@id
end
|
#inning ⇒ Object
Returns the value of attribute inning.
5
6
7
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 5
def inning
@inning
end
|
#number ⇒ Object
Returns the value of attribute number.
5
6
7
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 5
def number
@number
end
|
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 5
def response
@response
end
|
#type ⇒ Object
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_bats ⇒ Object
34
35
36
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 34
def at_bats
events.map(&:at_bat).compact
end
|
#error_count ⇒ Object
59
60
61
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 59
def error_count
errors.count
end
|
#errors ⇒ Object
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
|
#events ⇒ Object
42
43
44
45
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 42
def events
@events
end
|
#hit_count ⇒ Object
51
52
53
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 51
def hit_count
hits.count
end
|
#hits ⇒ Object
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_changes ⇒ Object
38
39
40
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 38
def lineup_changes
end
|
#over? ⇒ Boolean
26
27
28
|
# File 'lib/sportradar/api/baseball/half_inning.rb', line 26
def over?
pitches.last&.count&.dig('outs') == 3
end
|
#pitches ⇒ Object
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) }
end
|