Class: RaceClub

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

Class Method Summary collapse

Class Method Details

.find_by_any_name(name) ⇒ Object



23
24
25
# File 'app/models/race_club.rb', line 23

def self.find_by_any_name(name)
  by_name_or_alias(name).first
end

.find_or_create_by_any_name(name = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/models/race_club.rb', line 27

def self.find_or_create_by_any_name(name=nil)
  name = normalize_name(name)
  return if name.blank?
  return if %w{unattached ua u/a}.include? name.downcase
  unless club = find_by_any_name(name) 
    club = new(:name => name)
    club.save!
  end
  club
end

.normalize_name(name = "") ⇒ Object

TODO make this a lot more UTF-friendly: strip control characters and excel mmska without losing accents and symbols?



41
42
43
44
45
46
# File 'app/models/race_club.rb', line 41

def self.normalize_name(name="")
  name.gsub!(/\B&\B/, "and")
  name.gsub!(/\s+/, " ")
  name.gsub!(/[^A-Za-z -,]/, "")
  name.strip
end