class Alias

Alternate name for a Person or Team. Example: Erik Tonkin might have aliases of ‘Eric Tonkin,’ and ‘E. Tonkin’ Must belong to either a Person or Team, but not both. Used by Result when importing results from Excel. Aliases cannot be the same (“shadow”) as Person#name or Names::Nameable#name. This could probably be combined with Name.

Public Class Methods

export() click to toggle source
# File app/models/export/aliases.rb, line 5
def Alias.export
  Alias.export_head
  Alias.export_data
end
export_columns() click to toggle source
# File app/models/export/aliases.rb, line 34
def Alias.export_columns
  [
    "id", "alias", "name", "person_id", "team_id"
  ]
end
export_data() click to toggle source
# File app/models/export/aliases.rb, line 16
def Alias.export_data
  Base.export(Alias.export_data_sql, "aliases.csv")
end
export_data_sql() click to toggle source
# File app/models/export/aliases.rb, line 26
def Alias.export_data_sql
  "SELECT #{Alias.export_columns.join(",")}
   INTO OUTFILE '%s'
   FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
   LINES TERMINATED BY '\\n'
   FROM aliases"
end
export_head() click to toggle source
# File app/models/export/aliases.rb, line 12
def Alias.export_head
  Base.export(Alias.export_head_sql, "aliases.txt")
end
export_head_sql() click to toggle source
# File app/models/export/aliases.rb, line 20
def Alias.export_head_sql
  "SELECT '#{Alias.export_columns.join("','")}'
   INTO OUTFILE '%s'
   FIELDS TERMINATED BY '\\n'"
end
find_all_people_by_name(name) click to toggle source
# File app/models/alias.rb, line 15
def Alias.find_all_people_by_name(name)
  aliases = Alias.all( 
    :conditions => ['aliases.name = ? and person_id is not null', name],
    :include => :person
  )
  aliases.collect do |person_alias|
    person_alias.person
  end
end
find_all_teams_by_name(name) click to toggle source
# File app/models/alias.rb, line 25
def Alias.find_all_teams_by_name(name)
  aliases = Alias.all(
    :conditions => ['aliases.name = ? and team_id is not null', name],
    :include => :team
  )
  aliases.collect do |team_alias|
    team_alias.team
  end
end

Public Instance Methods

person_or_team() click to toggle source
# File app/models/alias.rb, line 35
def person_or_team
  unless (person && !team) || (!person && team)
    errors.add "person or team", "Must have exactly one person or team"
  end
end
to_s() click to toggle source
# File app/models/alias.rb, line 41
def to_s
  "<#{self.class.name} #{self[:id]} #{self[:name]} #{self[:person_id]} #{self[:team_id]}>"
end