Class: Sports::Goal

Inherits:
Object
  • Object
show all
Defined in:
lib/sports/structs/goal.rb

Overview

nested (non-freestanding) inside match (match is parent)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#minuteObject (readonly)

Returns the value of attribute minute.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def minute
  @minute
end

#notesObject (readonly)

Returns the value of attribute notes.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def notes
  @notes
end

#offsetObject (readonly)

Returns the value of attribute offset.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def offset
  @offset
end

#owngoalObject (readonly)

Returns the value of attribute owngoal.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def owngoal
  @owngoal
end

#penaltyObject (readonly)

Returns the value of attribute penalty.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def penalty
  @penalty
end

#playerObject (readonly)

Returns the value of attribute player.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def player
  @player
end

#score1Object (readonly)

Returns the value of attribute score1.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def score1
  @score1
end

#score2Object (readonly)

Returns the value of attribute score2.



190
191
192
# File 'lib/sports/structs/goal.rb', line 190

def score2
  @score2
end

#teamObject (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

Returns:

  • (Boolean)


202
# File 'lib/sports/structs/goal.rb', line 202

def owngoal?() @owngoal==true; end

#penalty?Boolean

Returns:

  • (Boolean)


203
# File 'lib/sports/structs/goal.rb', line 203

def penalty?() @penalty==true; end

#team1?Boolean

Returns:

  • (Boolean)


204
# File 'lib/sports/structs/goal.rb', line 204

def team1?()   @team == 1; end

#team2?Boolean

Returns:

  • (Boolean)


205
# File 'lib/sports/structs/goal.rb', line 205

def team2?()   @team == 2; end