Class: Tournament

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

Instance Method Summary collapse

Instance Method Details

#autofill(racer_list = nil) ⇒ Object



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

def autofill(racer_list=nil)
  racer_list ||= reload.unmatched_racers.to_a
  racer_list.each_slice($BIKES.length) { |a|
    race = Race.create(:tournament => self)
    a.map{|r| RaceParticipation.create(:racer => r, :race => race)}
  }
end

#matched_racersObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/opensprints-core/tournament.rb', line 22

def matched_racers
  matched = []
  matches = self.races.select{|race| race.unraced? }
  matches.each { |race|
    race.race_participations.each {|rp|
      matched << rp.racer
    }
  }
  matched
end

#never_raced_and_not_eliminatedObject

TODO: test



34
35
36
37
38
39
40
41
42
# File 'lib/opensprints-core/tournament.rb', line 34

def never_raced_and_not_eliminated
  matched = []
  races.each { |race|
    race.race_participations.each {|rp|
      matched << rp.racer
    }
  }
  racers - matched - tournament_participations.select{|tp|tp.eliminated}.map{|tp|tp.racer}
end

#unmatched_racersObject



18
19
20
# File 'lib/opensprints-core/tournament.rb', line 18

def unmatched_racers
  racers - matched_racers - tournament_participations.select{|tp|tp.eliminated}.map{|tp|tp.racer}
end

#unregistered_racersObject



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

def unregistered_racers
  Racer.exclude(:id => Racer.join(:tournament_participations, :racer_id => :id).select(:racers__id)).all
end