module Concerns::Result::Cleanup::InstanceMethods

Public Instance Methods

cleanup() click to toggle source

Fix common formatting mistakes and inconsistencies

# File app/models/concerns/result/cleanup.rb, line 8
def cleanup
  cleanup_place
  cleanup_number
  cleanup_license
  self.first_name = cleanup_name(first_name)
  self.last_name = cleanup_name(last_name)
  self.team_name = cleanup_name(team_name)
end
cleanup_license() click to toggle source
# File app/models/concerns/result/cleanup.rb, line 41
def cleanup_license
  self.license = license.to_s
  # USAC license numbers are being imported with a one decimal zero, e.g., 12345.0
  self.license = license.to_i.to_s if license[%r^\d+\.0$/]
end
cleanup_name(name) click to toggle source

Mostly removes unfortunate punctuation typos

# File app/models/concerns/result/cleanup.rb, line 48
def cleanup_name(name)
  return name if name.nil?
  name = name.to_s
  return '' if name == '0.0'
  return '' if name == '0'
  return '' if name == '.'
  return '' if name.include?('N/A')
  name = name.gsub(';', '\')
  name = name.gsub(%r *\/ */, '/')
end
cleanup_number() click to toggle source
# File app/models/concerns/result/cleanup.rb, line 36
def cleanup_number
  self.number = number.to_s
  self.number = number.to_i.to_s if number[%r^\d+\.0$/]
end
cleanup_place() click to toggle source

Drops the ‘st’ from 1st, among other things

# File app/models/concerns/result/cleanup.rb, line 18
def cleanup_place
  if place
    normalized_place = place.to_s.dup
    normalized_place.upcase!
    normalized_place.gsub!("ST", "")
    normalized_place.gsub!("ND", "")
    normalized_place.gsub!("RD", "")
    normalized_place.gsub!("TH", "")
    normalized_place.gsub!(")", "")
    normalized_place = normalized_place.to_i.to_s if normalized_place[%r^\d+\.0$/]
    normalized_place.strip!
    normalized_place.gsub!(".", "")
    self.place = normalized_place
  else
    self.place = ""
  end
end