Class: Stattleship::Models::ScoringPlay

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

Instance Method Summary collapse

Instance Method Details

#assist_namesObject


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

def assist_names
  if assists && assists.count > 0
    assists.map(&:player_name).join(', ')
  else
    'Unassisted'
  end
end

#assistsObject


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

def assists
  return unless scoring_players

  scoring_players.select do |scoring_player|
    scoring_player.role == 'assist'
  end
end

#atObject


124
125
126
# File 'lib/stattleship/models/scoring_play.rb', line 124

def at
  "#{period_time} of #{period}"
end

#away_teamObject


4
5
6
# File 'lib/stattleship/models/scoring_play.rb', line 4

def away_team
  game.away_team
end

#away_team_nameObject


16
17
18
# File 'lib/stattleship/models/scoring_play.rb', line 16

def away_team_name
  away_team.name
end

#cityObject


28
29
30
# File 'lib/stattleship/models/scoring_play.rb', line 28

def city
  venue.city
end

#home_teamObject


8
9
10
# File 'lib/stattleship/models/scoring_play.rb', line 8

def home_team
  game.home_team
end

#home_team_nameObject


20
21
22
# File 'lib/stattleship/models/scoring_play.rb', line 20

def home_team_name
  home_team.name
end

#league_abbreviationObject


36
37
38
# File 'lib/stattleship/models/scoring_play.rb', line 36

def league_abbreviation
  league.abbreviation
end

#league_nameObject


32
33
34
# File 'lib/stattleship/models/scoring_play.rb', line 32

def league_name
  league.name
end

#opponent_full_nameObject


48
49
50
# File 'lib/stattleship/models/scoring_play.rb', line 48

def opponent_full_name
  opponent.full_name
end

#opponent_nameObject


44
45
46
# File 'lib/stattleship/models/scoring_play.rb', line 44

def opponent_name
  opponent.name
end

#periodObject


120
121
122
# File 'lib/stattleship/models/scoring_play.rb', line 120

def period
  "#{period_number}#{period_abbreviation}"
end

#period_abbreviationObject


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

def period_abbreviation
  if game.hockey?
    "P"
  else
    "Q"
  end
end

#period_timeObject


108
109
110
# File 'lib/stattleship/models/scoring_play.rb', line 108

def period_time
  Time.at(period_seconds).utc.strftime('%M:%S')
end

#player_nameObject


40
41
42
# File 'lib/stattleship/models/scoring_play.rb', line 40

def player_name
  # player.name
end

#scorelineObject


52
53
54
# File 'lib/stattleship/models/scoring_play.rb', line 52

def scoreline
  game.scoreline
end

#scorerObject


80
81
82
# File 'lib/stattleship/models/scoring_play.rb', line 80

def scorer
  scorers.first if scorers
end

#scorer_nameObject


84
85
86
87
88
89
90
# File 'lib/stattleship/models/scoring_play.rb', line 84

def scorer_name
  if scorer
    scorer.player_name
  else
    ''
  end
end

#scorersObject


72
73
74
75
76
77
78
# File 'lib/stattleship/models/scoring_play.rb', line 72

def scorers
  return unless scoring_players

  scoring_players.select do |scoring_player|
    scoring_player.role == 'scorer'
  end
end

#scoring_player_namesObject


128
129
130
131
132
133
134
# File 'lib/stattleship/models/scoring_play.rb', line 128

def scoring_player_names
  if scoring_players
    scoring_players.map(&:player_name).join(', ')
  else
    ''
  end
end

#scoring_player_role_namesObject


136
137
138
139
140
141
142
# File 'lib/stattleship/models/scoring_play.rb', line 136

def scoring_player_role_names
  if scoring_players
    scoring_players.map(&:name).join(', ')
  else
    ''
  end
end

#scoring_players_infoObject


144
145
146
147
148
149
150
151
152
# File 'lib/stattleship/models/scoring_play.rb', line 144

def scoring_players_info
  if scoring_players
    player_names = scoring_players.map(&:player_name)
    role_names = scoring_players.map(&:name)
    player_names.zip(role_names).flatten.compact.join(', ')
  else
    ''
  end
end

#team_full_nameObject


60
61
62
# File 'lib/stattleship/models/scoring_play.rb', line 60

def team_full_name
  team.full_name
end

#team_nameObject


56
57
58
# File 'lib/stattleship/models/scoring_play.rb', line 56

def team_name
  team.name
end

#to_sentenceObject


160
161
162
163
164
165
166
167
168
# File 'lib/stattleship/models/scoring_play.rb', line 160

def to_sentence
  if game.hockey?
    "#{scorer_name} (#{assist_names}) - #{at} - #{vs}"
  elsif game.football?
    "#{period_number} QTR #{period_time} - #{points} points - #{yards} yards - #{scoring_players_info} - #{vs}"
  else
    ''
  end
end

#venueObject


64
65
66
# File 'lib/stattleship/models/scoring_play.rb', line 64

def venue
  game.venue
end

#venue_nameObject


68
69
70
# File 'lib/stattleship/models/scoring_play.rb', line 68

def venue_name
  venue.name
end

#vsObject


154
155
156
157
158
# File 'lib/stattleship/models/scoring_play.rb', line 154

def vs
  if game
    "vs #{opponent_name} #{game.short_date}"
  end
end

#winning_teamObject


12
13
14
# File 'lib/stattleship/models/scoring_play.rb', line 12

def winning_team
  game.winning_team
end

#winning_team_nameObject


24
25
26
# File 'lib/stattleship/models/scoring_play.rb', line 24

def winning_team_name
  winning_team.name
end