class SsnHighGroupCodeLoader

Public Class Methods

load_all_high_group_codes_files() { |status| ... } click to toggle source
# File lib/ssn_validator/models/ssn_high_group_code_loader.rb, line 4
def self.load_all_high_group_codes_files
  months = ['Jan','Feb','Mar','Apr','May','June','July','Aug',['Sept','Sep'],'Oct','Nov','Dec']
  run_file_date = SsnHighGroupCode.maximum(:as_of)
  run_file_date = run_file_date ? run_file_date.next_month.beginning_of_month.to_date : Date.new(2003,11,01)
  last_file_date = Date.today.beginning_of_month
  while run_file_date <= last_file_date
    file_processed = false
    run_file_month_variants = Array(months[run_file_date.month - 1])
    run_file_year =  run_file_date.year
    run_file_month_variants.each do |run_file_month|
      break if file_processed
      ['','corrected'].each do |mod|
        break if file_processed
        ['ssns','ssnvs'].each do |url_mod|
          break if file_processed
          (1..Date.today.day).each do |day|
            string_day = day.to_s
            string_day.insert(0,'0') if day < 10
            string_year = run_file_year.to_s.last(2)
            file_name = "HG#{run_file_month}#{string_day}#{string_year}#{mod}.txt"
            text = Net::HTTP.get(URI.parse("http://www.socialsecurity.gov/employer/#{url_mod}/#{file_name}"))
            unless text.include? 'File Not Found'
              create_records(parse_text(text),extract_as_of_date(text)) do |status|
                yield status if block_given?
              end
              file_processed = true
              break
            end
          end
        end
      end
    end
    run_file_date = run_file_date.next_month
  end
end
load_current_high_group_codes_file() click to toggle source

Loads the most recent file from www.socialsecurity.gov/employer/ssns/highgroup.txt

# File lib/ssn_validator/models/ssn_high_group_code_loader.rb, line 41
def self.load_current_high_group_codes_file
  text = Net::HTTP.get(URI.parse('http://www.socialsecurity.gov/employer/ssns/highgroup.txt'))
  create_records(parse_text(text),extract_as_of_date(text))
end