Class: Stattleship::Models::Game

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/stattleship/models/game.rb

Instance Method Summary collapse

Instance Method Details

#away_team_colorsObject


35
36
37
38
39
# File 'lib/stattleship/models/game.rb', line 35

def away_team_colors
  if away_team
    away_team.colors
  end
end

#away_team_nameObject


41
42
43
44
45
# File 'lib/stattleship/models/game.rb', line 41

def away_team_name
  if away_team
    away_team.name
  end
end

#away_team_slugObject


47
48
49
50
51
# File 'lib/stattleship/models/game.rb', line 47

def away_team_slug
  if away_team
    away_team.slug
  end
end

#baseball?Boolean

Returns:

  • (Boolean)

142
143
144
# File 'lib/stattleship/models/game.rb', line 142

def baseball?
  league.baseball?
end

#basketball?Boolean

Returns:

  • (Boolean)

146
147
148
# File 'lib/stattleship/models/game.rb', line 146

def basketball?
  league.basketball?
end

#cityObject


4
5
6
7
8
# File 'lib/stattleship/models/game.rb', line 4

def city
  if venue
    venue.city
  end
end

#colorsObject


10
11
12
13
14
15
# File 'lib/stattleship/models/game.rb', line 10

def colors
  [away_team_colors, home_team_colors].
    flatten.
    compact.
    uniq
end

#coordinatesObject


188
189
190
# File 'lib/stattleship/models/game.rb', line 188

def coordinates
  [latitude, longitude]
end

#dumpObject


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/stattleship/models/game.rb', line 255

def dump
  {
    at_neutral_site: at_neutral_site,
    away_team_colors: away_team_colors,
    away_team_name: away_team_name,
    away_team_outcome: away_team_outcome,
    away_team_slug: away_team_slug,
    city: city,
    colors: colors,
    coordinates: coordinates,
    daytime: daytime,
    home_team_colors: home_team_colors,
    home_team_name: home_team_name,
    home_team_outcome: home_team_outcome,
    home_team_slug: home_team_slug,
    interval: interval,
    interval_type: interval_type,
    label: label,
    latitude: latitude,
    longitude: longitude,
    league_abbreviation: league_abbreviation,
    league_name: league_name,
    losing_score: losing_score,
    losing_scoreline: losing_scoreline,
    losing_team_colors: losing_team_colors,
    losing_team_score: losing_team_score,
    losing_team_slug: losing_team_slug,
    losing_team: losing_team.hash,
    name: name,
    on: on,
    score: score,
    scoreline: scoreline,
    sentence: to_sentence,
    short_date: short_date,
    slug: slug,
    sport: sport,
    state: state,
    status: status,
    team_slugs: team_slugs,
    temperature_unit: temperature_unit,
    title: title,
    venue_capacity: venue_capacity,
    venue_name: venue_name,
    venue_slug: venue_slug,
    weather_conditions: weather_conditions,
    wind_direction: wind_direction,
    wind_speed: wind_speed,
    wind_speed_unit: wind_speed_unit,
    winning_score: winning_score,
    winning_scoreline: winning_scoreline,
    winning_team_colors: winning_team_colors,
    winning_team_name: winning_team_name,
    winning_team_score: winning_team_score,
    winning_team_slug: winning_team_slug,
    winning_team: winning_team_hash,
  }
end

#football?Boolean

Returns:

  • (Boolean)

150
151
152
# File 'lib/stattleship/models/game.rb', line 150

def football?
  league.football?
end

#game_clockObject


243
244
245
246
247
248
249
# File 'lib/stattleship/models/game.rb', line 243

def game_clock
  if sport == 'baseball'
    "#{top_or_bottom} #{period.ordinalize} #{period_label}"
  else
    "#{clock} #{period.ordinalize} #{period_label}"
  end
end

#hockey?Boolean

Returns:

  • (Boolean)

138
139
140
# File 'lib/stattleship/models/game.rb', line 138

def hockey?
  league.hockey?
end

#home_team_colorsObject


53
54
55
56
57
# File 'lib/stattleship/models/game.rb', line 53

def home_team_colors
  if home_team
    home_team.colors
  end
end

#home_team_nameObject


59
60
61
62
63
# File 'lib/stattleship/models/game.rb', line 59

def home_team_name
  if home_team
    home_team.name
  end
end

#home_team_slugObject


65
66
67
68
69
# File 'lib/stattleship/models/game.rb', line 65

def home_team_slug
  if home_team
    home_team.slug
  end
end

#latitudeObject


176
177
178
179
180
# File 'lib/stattleship/models/game.rb', line 176

def latitude
  if venue
    venue.latitude
  end
end

#league_abbreviationObject


29
30
31
32
33
# File 'lib/stattleship/models/game.rb', line 29

def league_abbreviation
  if league
    league.abbreviation
  end
end

#league_nameObject


23
24
25
26
27
# File 'lib/stattleship/models/game.rb', line 23

def league_name
  if league
    league.name
  end
end

#longitudeObject


182
183
184
185
186
# File 'lib/stattleship/models/game.rb', line 182

def longitude
  if venue
    venue.longitude
  end
end

#losing_scoreObject


192
193
194
195
196
197
198
199
# File 'lib/stattleship/models/game.rb', line 192

def losing_score
  if score
    score.split('-').
      map(&:to_i).
      sort.
      join('-')
  end
end

#losing_scorelineObject


227
228
229
230
231
232
233
# File 'lib/stattleship/models/game.rb', line 227

def losing_scoreline
  if winning_team && losing_team
    "#{losing_team.nickname} #{losing_team_score} - #{winning_team.nickname} #{winning_team_score}"
  else
    ''
  end
end

#losing_teamObject


118
119
120
121
122
123
124
# File 'lib/stattleship/models/game.rb', line 118

def losing_team
  if home_team_slug == winning_team_slug
    away_team
  else
    home_team
  end
end

#losing_team_colorsObject


112
113
114
115
116
# File 'lib/stattleship/models/game.rb', line 112

def losing_team_colors
  if losing_team
    losing_team.colors
  end
end

#losing_team_hashObject


106
107
108
109
110
# File 'lib/stattleship/models/game.rb', line 106

def losing_team_hash
  if losing_team
    losing_team.dump
  end
end

#losing_team_nameObject


126
127
128
129
130
# File 'lib/stattleship/models/game.rb', line 126

def losing_team_name
  if losing_team
    losing_team.name
  end
end

#losing_team_scoreObject


215
216
217
# File 'lib/stattleship/models/game.rb', line 215

def losing_team_score
  [away_team_score, home_team_score].min
end

#losing_team_slugObject


132
133
134
135
136
# File 'lib/stattleship/models/game.rb', line 132

def losing_team_slug
  if losing_team
    losing_team.slug
  end
end

#short_dateObject


154
155
156
# File 'lib/stattleship/models/game.rb', line 154

def short_date
  started_at.strftime('%m/%d/%y')
end

#sportObject


17
18
19
20
21
# File 'lib/stattleship/models/game.rb', line 17

def sport
  if league
    league.sport
  end
end

#stateObject


71
72
73
74
75
# File 'lib/stattleship/models/game.rb', line 71

def state
  if venue
    venue.state
  end
end

#team_slugsObject


77
78
79
80
# File 'lib/stattleship/models/game.rb', line 77

def team_slugs
  [away_team_slug,
   home_team_slug].compact
end

#to_sentenceObject


251
252
253
# File 'lib/stattleship/models/game.rb', line 251

def to_sentence
  "#{winning_team_name} won #{winning_score} on #{short_date}"
end

#top_or_bottomObject


235
236
237
238
239
240
241
# File 'lib/stattleship/models/game.rb', line 235

def top_or_bottom
  if clock == ':30'
    'Bottom'
  else
    'Top'
  end
end

#venue_capacityObject


158
159
160
161
162
# File 'lib/stattleship/models/game.rb', line 158

def venue_capacity
  if venue
    venue.capacity
  end
end

#venue_nameObject


164
165
166
167
168
# File 'lib/stattleship/models/game.rb', line 164

def venue_name
  if venue
    venue.name
  end
end

#venue_slugObject


170
171
172
173
174
# File 'lib/stattleship/models/game.rb', line 170

def venue_slug
  if venue
    venue.slug
  end
end

#winning_scoreObject


201
202
203
204
205
206
207
208
209
# File 'lib/stattleship/models/game.rb', line 201

def winning_score
  if score
    score.split('-').
      map(&:to_i).
      sort.
      reverse.
      join('-')
  end
end

#winning_scorelineObject


219
220
221
222
223
224
225
# File 'lib/stattleship/models/game.rb', line 219

def winning_scoreline
  if winning_team && losing_team
    "#{winning_team.nickname} #{winning_team_score} - #{losing_team.nickname} #{losing_team_score}"
  else
    ''
  end
end

#winning_team_colorsObject


82
83
84
85
86
# File 'lib/stattleship/models/game.rb', line 82

def winning_team_colors
  if winning_team
    winning_team.colors
  end
end

#winning_team_hashObject


100
101
102
103
104
# File 'lib/stattleship/models/game.rb', line 100

def winning_team_hash
  if winning_team
    winning_team.dump
  end
end

#winning_team_nameObject


88
89
90
91
92
# File 'lib/stattleship/models/game.rb', line 88

def winning_team_name
  if winning_team
    winning_team.name
  end
end

#winning_team_scoreObject


211
212
213
# File 'lib/stattleship/models/game.rb', line 211

def winning_team_score
  [away_team_score, home_team_score].max
end

#winning_team_slugObject


94
95
96
97
98
# File 'lib/stattleship/models/game.rb', line 94

def winning_team_slug
  if winning_team
    winning_team.slug
  end
end