Class: SsnHighGroupCodeLoader

Inherits:
Object
  • Object
show all
Defined in:
app/models/ssn_high_group_code_loader.rb

Class Method Summary collapse

Class Method Details

.load_all_high_group_codes_filesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/ssn_high_group_code_loader.rb', line 5

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_fileObject

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



42
43
44
45
# File 'app/models/ssn_high_group_code_loader.rb', line 42

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