Class: Sports::Goal
- Inherits:
-
Object
- Object
- Sports::Goal
- Defined in:
- lib/sportdb/quick/csv/goal.rb
Overview
extend “basic” goal struct with goal event build
Class Method Summary collapse
-
.build(events) ⇒ Object
nested (non-freestanding) inside match (match is parent).
Class Method Details
.build(events) ⇒ Object
nested (non-freestanding) inside match (match is parent)
146 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 |
# File 'lib/sportdb/quick/csv/goal.rb', line 146 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 << new( **attributes ) end recs end |