Class: Sports::Goal
- Inherits:
-
Object
- Object
- Sports::Goal
- Defined in:
- lib/sports/structs/goal.rb
Overview
nested (non-freestanding) inside match (match is parent)
Instance Attribute Summary collapse
-
#minute ⇒ Object
readonly
Returns the value of attribute minute.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#owngoal ⇒ Object
readonly
Returns the value of attribute owngoal.
-
#penalty ⇒ Object
readonly
Returns the value of attribute penalty.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#score1 ⇒ Object
readonly
Returns the value of attribute score1.
-
#score2 ⇒ Object
readonly
Returns the value of attribute score2.
-
#team ⇒ Object
readonly
Returns the value of attribute team.
Class Method Summary collapse
-
.build(events) ⇒ Object
check/todo - rename to build_from_event/row or such - why? why not?.
Instance Method Summary collapse
-
#initialize(score1:, score2:, team:, player:, minute:, offset: nil, owngoal: false, penalty: false, notes: nil) ⇒ Goal
constructor
A new instance of Goal.
- #owngoal? ⇒ Boolean
- #penalty? ⇒ Boolean
- #team1? ⇒ Boolean
- #team2? ⇒ Boolean
Constructor Details
#initialize(score1:, score2:, team:, player:, minute:, offset: nil, owngoal: false, penalty: false, notes: nil) ⇒ Goal
Returns a new instance of Goal.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/sports/structs/goal.rb', line 207 def initialize( score1:, score2:, team:, player:, minute:, offset: nil, owngoal: false, penalty: false, notes: nil ) @score1 = score1 @score2 = score2 @team = team # 1 or 2 @player = player @minute = minute @offset = offset @owngoal = owngoal @penalty = penalty @notes = notes end |
Instance Attribute Details
#minute ⇒ Object (readonly)
Returns the value of attribute minute.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def minute @minute end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def notes @notes end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def offset @offset end |
#owngoal ⇒ Object (readonly)
Returns the value of attribute owngoal.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def owngoal @owngoal end |
#penalty ⇒ Object (readonly)
Returns the value of attribute penalty.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def penalty @penalty end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def player @player end |
#score1 ⇒ Object (readonly)
Returns the value of attribute score1.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def score1 @score1 end |
#score2 ⇒ Object (readonly)
Returns the value of attribute score2.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def score2 @score2 end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
190 191 192 |
# File 'lib/sports/structs/goal.rb', line 190 def team @team end |
Class Method Details
.build(events) ⇒ Object
check/todo - rename to build_from_event/row or such - why? why not?
147 148 149 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 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/sports/structs/goal.rb', line 147 def self.build( events ) ## check/todo - rename to build_from_event/row or such - why? why not? ## build an array of goal structs from (csv) recs recs = [] last_score1 = 0 last_score2 = 0 events.each do |event| if last_score1+1 == event.score1 && last_score2 == event.score2 team = 1 elsif last_score2+1 == event.score2 && last_score1 == event.score1 team = 2 else puts "!! ERROR - unexpected score advance (one goal at a time expected):" puts " #{last_score1}-#{last_score2}=> #{event.score1}-#{event.score2}" exit 1 end last_score1 = event.score1 last_score2 = event.score2 attributes = { score1: event.score1, score2: event.score2, team: team, minute: event.minute, offset: event.offset, player: event.player, owngoal: event.owngoal, penalty: event.penalty, notes: event.notes } recs << Goal.new( **attributes ) end recs end |
Instance Method Details
#owngoal? ⇒ Boolean
202 |
# File 'lib/sports/structs/goal.rb', line 202 def owngoal?() @owngoal==true; end |
#penalty? ⇒ Boolean
203 |
# File 'lib/sports/structs/goal.rb', line 203 def penalty?() @penalty==true; end |
#team1? ⇒ Boolean
204 |
# File 'lib/sports/structs/goal.rb', line 204 def team1?() @team == 1; end |
#team2? ⇒ Boolean
205 |
# File 'lib/sports/structs/goal.rb', line 205 def team2?() @team == 2; end |