Class: Race

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/race.rb

Instance Method Summary collapse

Instance Method Details

#checkpoint_after(cp) ⇒ Object



63
64
65
# File 'app/models/race.rb', line 63

def checkpoint_after(cp)
  checkpoints.at(checkpoints.index(cp) + 1) if checkpoints.include?(cp) and checkpoints.last != cp
end

#checkpoint_before(cp) ⇒ Object



59
60
61
# File 'app/models/race.rb', line 59

def checkpoint_before(cp)
  checkpoints.at(checkpoints.index(cp) - 1) if checkpoints.include?(cp) and checkpoints.first != cp
end

#in(name) ⇒ Object



42
43
44
# File 'app/models/race.rb', line 42

def in(name)
  instances.find_by_name(name)
end

#latestObject



38
39
40
# File 'app/models/race.rb', line 38

def latest
  instances.past.first   # they sort by start time desc
end

#nextObject



46
47
48
# File 'app/models/race.rb', line 46

def next
  instances.future.first
end

#record(category_name = "M") ⇒ Object



50
51
52
53
54
55
56
57
# File 'app/models/race.rb', line 50

def record(category_name="M")
  category = RaceCategory.find_or_create_by_normalized_name(category_name)
  if new_record?
    self.records.build(:race_category => category)
  else 
    RaceRecord.find_or_create_by_race_id_and_race_category_id(self.id, category.id)
  end
end

#to_paramObject



34
35
36
# File 'app/models/race.rb', line 34

def to_param
  slug
end