Class: RaceCategory

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create_by_normalized_name(name) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/race_category.rb', line 64

def self.find_or_create_by_normalized_name(name)
  name = normalized_name(name)
  unless category = find_by_name(name)
    category = new(:name => name)
    if matches = name.match(/^([A-Z]+)(\d*)$/)
      if matches[2] 
        category.send(matches[1].match(/U/) ? :age_below= : :age_above=, matches[2])
      end
      category.gender = matches[1].match(/L/) ? "F" : "M"
    end
    category.save!
  end
  category
end

Instance Method Details

#to_paramObject



60
61
62
# File 'app/models/race_category.rb', line 60

def to_param
  name
end