Class: Sportradar::Mlb::Models::Pitch

Inherits:
Object
  • Object
show all
Defined in:
lib/sportradar/mlb/models/pitch.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes:) ⇒ Pitch

Returns a new instance of Pitch.



5
6
7
# File 'lib/sportradar/mlb/models/pitch.rb', line 5

def initialize(attributes:)
  @attributes = attributes
end

Class Method Details

.from_at_bats(game_id:, at_bats: []) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/sportradar/mlb/models/pitch.rb', line 150

def self.from_at_bats(game_id:, at_bats: [])
  [].tap do |pitches|
    at_bats.each do |at_bat|
      at_bat.events.each do |event|
        if event['type'] == 'pitch' && event['status'] == 'official'
          pitches << new(attributes: event['pitcher'].
                                       merge('game_id' => game_id).
                                       merge('at_bat_id' => at_bat.id,
                                             'event_id' => event['id'],
                                             'pitched_at' => event['created_at'],
                                             'pitcher_id' => event['pitcher']['id'],
                                             'pitch_outcome_type' => event['outcome_id'],
                                             'hitter_id' => at_bat.hitter_id,
                                             'hit_type' => event['hit_type'],
                                             'hit_location' => event['hit_location']).
                                       merge((event['count'] || {}).transform_keys { |key| key.dup.to_s.prepend('at_bat_') }).
                                       merge(event['flags']).
                                       merge(at_bat.time_code).
                                       merge('pitch_outcome' => PitchOutcome.new(outcome: event['outcome_id']).
                                                                  to_s).
                                       except('id'))
        end
      end
    end
  end
end

Instance Method Details

#at_bat?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/sportradar/mlb/models/pitch.rb', line 81

def at_bat?
  attributes['is_ab'] || false
end

#at_bat_ballsObject



13
14
15
# File 'lib/sportradar/mlb/models/pitch.rb', line 13

def at_bat_balls
  attributes['at_bat_balls'] || 0
end

#at_bat_idObject



45
46
47
# File 'lib/sportradar/mlb/models/pitch.rb', line 45

def at_bat_id
  attributes['at_bat_id']
end

#at_bat_outsObject



17
18
19
# File 'lib/sportradar/mlb/models/pitch.rb', line 17

def at_bat_outs
  attributes['at_bat_outs'] || 0
end

#at_bat_over?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/sportradar/mlb/models/pitch.rb', line 85

def at_bat_over?
  attributes['is_ab_over'] || false
end

#at_bat_pitch_countObject



21
22
23
# File 'lib/sportradar/mlb/models/pitch.rb', line 21

def at_bat_pitch_count
  attributes['at_bat_pitch_count'] || 0
end

#at_bat_strikesObject



25
26
27
# File 'lib/sportradar/mlb/models/pitch.rb', line 25

def at_bat_strikes
  attributes['at_bat_strikes'] || 0
end

#bunt?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/sportradar/mlb/models/pitch.rb', line 89

def bunt?
  attributes['is_bunt'] || false
end

#bunt_shown?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/sportradar/mlb/models/pitch.rb', line 93

def bunt_shown?
  attributes['is_bunt_shown'] || false
end

#double_play?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/sportradar/mlb/models/pitch.rb', line 97

def double_play?
  attributes['is_double_play'] || false
end

#event_idObject



49
50
51
# File 'lib/sportradar/mlb/models/pitch.rb', line 49

def event_id
  attributes['event_id']
end

#game_idObject



53
54
55
# File 'lib/sportradar/mlb/models/pitch.rb', line 53

def game_id
  attributes['game_id']
end

#halfObject



129
130
131
# File 'lib/sportradar/mlb/models/pitch.rb', line 129

def half
  attributes['half'] || ''
end

#hit?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/sportradar/mlb/models/pitch.rb', line 101

def hit?
  attributes['is_hit'] || false
end

#hit_locationObject



73
74
75
# File 'lib/sportradar/mlb/models/pitch.rb', line 73

def hit_location
  attributes['hit_location']
end

#hit_typeObject



69
70
71
# File 'lib/sportradar/mlb/models/pitch.rb', line 69

def hit_type
  attributes['hit_type']
end

#hitter_idObject



65
66
67
# File 'lib/sportradar/mlb/models/pitch.rb', line 65

def hitter_id
  attributes['hitter_id']
end

#inningObject



125
126
127
# File 'lib/sportradar/mlb/models/pitch.rb', line 125

def inning
  attributes['inning'] || 0
end

#numberObject



121
122
123
# File 'lib/sportradar/mlb/models/pitch.rb', line 121

def number
  attributes['number'] || 0
end

#on_base?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/sportradar/mlb/models/pitch.rb', line 105

def on_base?
  attributes['is_on_base'] || false
end

#passed_ball?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/sportradar/mlb/models/pitch.rb', line 109

def passed_ball?
  attributes['is_passed_ball'] || false
end

#pitch_countObject



29
30
31
# File 'lib/sportradar/mlb/models/pitch.rb', line 29

def pitch_count
  attributes['pitch_count'] || 0
end

#pitch_nameObject



145
146
147
148
# File 'lib/sportradar/mlb/models/pitch.rb', line 145

def pitch_name
  PitchType.new(pitch_type: pitch_type).
    name || ''
end

#pitch_outcomeObject



137
138
139
# File 'lib/sportradar/mlb/models/pitch.rb', line 137

def pitch_outcome
  attributes['pitch_outcome'] || ''
end

#pitch_outcome_typeObject



61
62
63
# File 'lib/sportradar/mlb/models/pitch.rb', line 61

def pitch_outcome_type
  attributes['pitch_outcome_type']
end

#pitch_speedObject



33
34
35
# File 'lib/sportradar/mlb/models/pitch.rb', line 33

def pitch_speed
  attributes['pitch_speed'] || 0
end

#pitch_typeObject



37
38
39
# File 'lib/sportradar/mlb/models/pitch.rb', line 37

def pitch_type
  attributes['pitch_type'] || ''
end

#pitch_zoneObject



41
42
43
# File 'lib/sportradar/mlb/models/pitch.rb', line 41

def pitch_zone
  attributes['pitch_zone'] || ''
end

#pitched_atObject



77
78
79
# File 'lib/sportradar/mlb/models/pitch.rb', line 77

def pitched_at
  attributes['pitched_at']
end

#pitcher_idObject



57
58
59
# File 'lib/sportradar/mlb/models/pitch.rb', line 57

def pitcher_id
  attributes['pitcher_id']
end

#sequenceObject



133
134
135
# File 'lib/sportradar/mlb/models/pitch.rb', line 133

def sequence
  attributes['sequence'] || 0
end

#to_sObject



9
10
11
# File 'lib/sportradar/mlb/models/pitch.rb', line 9

def to_s
  "#{pitch_name} = #{pitch_outcome}"
end

#triple_play?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/sportradar/mlb/models/pitch.rb', line 113

def triple_play?
  attributes['is_triple_play'] || false
end

#wild_pitch?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/sportradar/mlb/models/pitch.rb', line 117

def wild_pitch?
  attributes['is_wild_pitch'] || false
end