class Discipline

Road, track, criterium, time trial … Cached. Call reset to clear cache.

Constants

NONE

Public Class Methods

[](name) click to toggle source

Look up Discipline by name or alias. Caches Disciplines in memory

# File app/models/discipline.rb, line 16
def self.[](name)
  return nil unless name
  load_aliases unless @@all_aliases
  if name.is_a?(Symbol)
    @@all_aliases[name]
  else
    return nil if name.blank?
    @@all_aliases[name.underscore.gsub(' ', '_').to_sym]
  end
end
find_all_bar() click to toggle source
# File app/models/discipline.rb, line 27
def self.find_all_bar
  Discipline.all( :conditions => ["bar = true"])
end
find_via_alias(name) click to toggle source
# File app/models/discipline.rb, line 31
def self.find_via_alias(name)
  Discipline[name]
end
load_aliases() click to toggle source
# File app/models/discipline.rb, line 35
def self.load_aliases
  @@all_aliases = {}
  results = connection.select_all(
    "SELECT discipline_id, alias FROM discipline_aliases"
  )
  for result in results
    @@all_aliases[result["alias"].underscore.gsub(' ', '_').to_sym] = Discipline.find(result["discipline_id"].to_i)
  end
  Discipline.all.each do |discipline|
    @@all_aliases[discipline.name.gsub(' ', '_').underscore.to_sym] = discipline
  end
end
names() click to toggle source
# File app/models/discipline.rb, line 54
def self.names
  @@names ||= Discipline.all.map(&:name)
end
reset() click to toggle source

Clear out cached @@aliases

# File app/models/discipline.rb, line 49
def self.reset
  @@all_aliases = nil
  @@names = nil
end

Public Instance Methods

<=>(other) click to toggle source
# File app/models/discipline.rb, line 73
def <=>(other)
  name <=> other.name
end
names() click to toggle source
# File app/models/discipline.rb, line 58
def names
  case name
  when "Road"
    [ nil, "", 'Circuit', "Criterium", "Road", "Time Trial", "Singlespeed", "Tour" ]
  when "Mountain Bike"
    [ 'Downhill', 'Mountain Bike', 'Super D', "Short Track" ]
  else
    [ name ]
  end
end
to_param() click to toggle source
# File app/models/discipline.rb, line 69
def to_param
  @param || @param = name.underscore.gsub(' ', '_')
end
to_s() click to toggle source
# File app/models/discipline.rb, line 77
def to_s
  "<#{self.class} #{id} #{name}>"
end