Class: Sportradar::Nhl::Models::Event
- Inherits:
-
Object
- Object
- Sportradar::Nhl::Models::Event
- Defined in:
- lib/sportradar/nhl/models/event.rb
Direct Known Subclasses
Constant Summary collapse
- EVENT_TYPES =
%w(emptynetgoal endperiod endshootoutperiod evenstrength faceoff giveaway goal goaliechange hit penalty penaltygoal penaltyshotmissed penaltyshotsaved powerplay shootoutgoal shootoutshotmissed shootoutshotsaved shotmissed shotsaved startshootoutperiod stoppage takeaway teamtimeout tvtimeout)
- PLAY_TYPES =
%w(emptynetgoal faceoff giveaway goal hit penalty penaltygoal penaltyshotmissed penaltyshotsaved powerplay shootoutgoal shootoutshotmissed shootoutshotsaved shotmissed shotsaved takeaway)
- STOPPAGE_TYPES =
%w(stoppage teamtimeout tvtimeout endperiod)
- SCORING_PLAY_TYPES =
%w(goal penaltygoal shootoutgoal)
- PENALTY_TYPES =
%w(penalty)
Instance Method Summary collapse
- #clock ⇒ Object
- #clock_secs ⇒ Object (also: #period_seconds)
- #coordinate_x ⇒ Object
- #coordinate_y ⇒ Object
- #coordinates ⇒ Object
- #coordinates? ⇒ Boolean
- #description ⇒ Object
- #event_type ⇒ Object
- #game_id ⇒ Object
- #has_team? ⇒ Boolean
- #id ⇒ Object
-
#initialize(period:, attributes:) ⇒ Event
constructor
A new instance of Event.
- #official ⇒ Object
- #penalty? ⇒ Boolean
- #period ⇒ Object
- #period_abbreviation ⇒ Object
- #period_id ⇒ Object
- #period_number ⇒ Object
- #period_sequence ⇒ Object
- #period_type ⇒ Object
- #play? ⇒ Boolean
- #play_player_stats ⇒ Object
- #scoring_play? ⇒ Boolean
- #scoring_players ⇒ Object
- #statistics ⇒ Object
- #stoppage? ⇒ Boolean
- #strength ⇒ Object
- #team ⇒ Object
- #team_goal_side ⇒ Object
- #team_id ⇒ Object
- #time_code ⇒ Object
- #to_s ⇒ Object
- #updated_at ⇒ Object
- #wall_clock ⇒ Object
- #zone ⇒ Object
Constructor Details
#initialize(period:, attributes:) ⇒ Event
Returns a new instance of Event.
12 13 14 15 16 |
# File 'lib/sportradar/nhl/models/event.rb', line 12 def initialize(period:, attributes:) @period = period @attributes = attributes build_statistics end |
Instance Method Details
#clock ⇒ Object
79 80 81 |
# File 'lib/sportradar/nhl/models/event.rb', line 79 def clock @attributes['clock'] || '0' end |
#clock_secs ⇒ Object Also known as: period_seconds
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sportradar/nhl/models/event.rb', line 83 def clock_secs begin if clock && clock.include?(':') mins, secs = clock.split(':').map(&:to_i) Time.parse("00:#{mins}:#{secs}"). seconds_since_midnight.to_i end rescue => e return 0 end end |
#coordinate_x ⇒ Object
116 117 118 |
# File 'lib/sportradar/nhl/models/event.rb', line 116 def coordinate_x coordinates['coord_x'] end |
#coordinate_y ⇒ Object
120 121 122 |
# File 'lib/sportradar/nhl/models/event.rb', line 120 def coordinate_y coordinates['coord_y'] end |
#coordinates ⇒ Object
108 109 110 |
# File 'lib/sportradar/nhl/models/event.rb', line 108 def coordinates @attributes['location'] || {} end |
#coordinates? ⇒ Boolean
112 113 114 |
# File 'lib/sportradar/nhl/models/event.rb', line 112 def coordinates? @attributes['location'].present? end |
#description ⇒ Object
100 101 102 |
# File 'lib/sportradar/nhl/models/event.rb', line 100 def description @attributes['description'] || 0 end |
#event_type ⇒ Object
104 105 106 |
# File 'lib/sportradar/nhl/models/event.rb', line 104 def event_type @attributes['event_type'] end |
#game_id ⇒ Object
30 31 32 |
# File 'lib/sportradar/nhl/models/event.rb', line 30 def game_id period.game_id end |
#has_team? ⇒ Boolean
46 47 48 |
# File 'lib/sportradar/nhl/models/event.rb', line 46 def has_team? !team_id.nil? end |
#id ⇒ Object
26 27 28 |
# File 'lib/sportradar/nhl/models/event.rb', line 26 def id @attributes['id'] end |
#official ⇒ Object
124 125 126 |
# File 'lib/sportradar/nhl/models/event.rb', line 124 def official @attributes['official'] end |
#penalty? ⇒ Boolean
156 157 158 |
# File 'lib/sportradar/nhl/models/event.rb', line 156 def penalty? PENALTY_TYPES.include?(event_type) end |
#period ⇒ Object
50 51 52 |
# File 'lib/sportradar/nhl/models/event.rb', line 50 def period @period end |
#period_abbreviation ⇒ Object
58 59 60 |
# File 'lib/sportradar/nhl/models/event.rb', line 58 def period_abbreviation @period.abbreviation end |
#period_id ⇒ Object
54 55 56 |
# File 'lib/sportradar/nhl/models/event.rb', line 54 def period_id @period.id end |
#period_number ⇒ Object
62 63 64 |
# File 'lib/sportradar/nhl/models/event.rb', line 62 def period_number @period.number end |
#period_sequence ⇒ Object
66 67 68 |
# File 'lib/sportradar/nhl/models/event.rb', line 66 def period_sequence @period.sequence end |
#period_type ⇒ Object
70 71 72 |
# File 'lib/sportradar/nhl/models/event.rb', line 70 def period_type @period.type end |
#play? ⇒ Boolean
160 161 162 |
# File 'lib/sportradar/nhl/models/event.rb', line 160 def play? PLAY_TYPES.include?(event_type) end |
#play_player_stats ⇒ Object
148 149 150 |
# File 'lib/sportradar/nhl/models/event.rb', line 148 def play_player_stats @play_player_stats ||= [] end |
#scoring_play? ⇒ Boolean
164 165 166 |
# File 'lib/sportradar/nhl/models/event.rb', line 164 def scoring_play? SCORING_PLAY_TYPES.include?(event_type) end |
#scoring_players ⇒ Object
152 153 154 |
# File 'lib/sportradar/nhl/models/event.rb', line 152 def scoring_players @scoring_players ||= [] end |
#statistics ⇒ Object
144 145 146 |
# File 'lib/sportradar/nhl/models/event.rb', line 144 def statistics @attributes['statistics'] || [] end |
#stoppage? ⇒ Boolean
168 169 170 |
# File 'lib/sportradar/nhl/models/event.rb', line 168 def stoppage? STOPPAGE_TYPES.include?(event_type) end |
#strength ⇒ Object
128 129 130 |
# File 'lib/sportradar/nhl/models/event.rb', line 128 def strength @attributes['strength'] end |
#team ⇒ Object
34 35 36 |
# File 'lib/sportradar/nhl/models/event.rb', line 34 def team @attributes['attribution'] || {} end |
#team_goal_side ⇒ Object
42 43 44 |
# File 'lib/sportradar/nhl/models/event.rb', line 42 def team_goal_side team.dig('team_goal') end |
#team_id ⇒ Object
38 39 40 |
# File 'lib/sportradar/nhl/models/event.rb', line 38 def team_id team.dig('id') end |
#time_code ⇒ Object
74 75 76 77 |
# File 'lib/sportradar/nhl/models/event.rb', line 74 def time_code min, sec = clock.split(':').map(&:to_i) "PT#{min}M#{sec}S" end |
#to_s ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sportradar/nhl/models/event.rb', line 18 def to_s if coordinates? "#{period_abbreviation} - #{clock} - #{event_type}: #{description} [#{coordinate_x}, #{coordinate_y}]" else "#{period_abbreviation} - #{clock} - #{event_type}: #{description}" end end |
#updated_at ⇒ Object
140 141 142 |
# File 'lib/sportradar/nhl/models/event.rb', line 140 def updated_at @attributes['updated'] end |
#wall_clock ⇒ Object
132 133 134 |
# File 'lib/sportradar/nhl/models/event.rb', line 132 def wall_clock @attributes['wall_clock'] end |
#zone ⇒ Object
136 137 138 |
# File 'lib/sportradar/nhl/models/event.rb', line 136 def zone @attributes['zone'] end |