Class: Race

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/opensprints-core/race.rb

Instance Method Summary collapse

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/opensprints-core/race.rb', line 6

def finished?
  race_participations.all?(&:finish_time)
end

#next_raceObject



23
24
25
# File 'lib/opensprints-core/race.rb', line 23

def next_race
  (Race.filter(:raced => false, :tournament_id => tournament.pk).all - [self]).first
end

#unraced?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/opensprints-core/race.rb', line 19

def unraced?
  !raced
end

#winnerObject



10
11
12
13
14
15
16
17
# File 'lib/opensprints-core/race.rb', line 10

def winner
  if unraced?
    return nil
  else
    standings = self.race_participations.sort_by { |racer| racer.finish_time||Infinity }
    standings.first
  end
end