Class: OfacSdnLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ofac/models/ofac_sdn_loader.rb

Class Method Summary collapse

Class Method Details

.load_current_sdn_fileObject



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
# File 'lib/ofac/models/ofac_sdn_loader.rb', line 9

def self.load_current_sdn_file
  puts "Reloading OFAC sdn data"
  puts "Downloading OFAC data from http://www.treas.gov/offices/enforcement/ofac/sdn"
  #get the 3 data files
  sdn = Tempfile.new('sdn')
  sdn.write(Net::HTTP.get(URI.parse('http://www.treas.gov/offices/enforcement/ofac/sdn/delimit/sdn.pip')))
  sdn.rewind
  address = Tempfile.new('sdn')
  address.write(Net::HTTP.get(URI.parse('http://www.treas.gov/offices/enforcement/ofac/sdn/delimit/add.pip')))
  address.rewind
  alt = Tempfile.new('sdn')
  alt.write(Net::HTTP.get(URI.parse('http://www.treas.gov/offices/enforcement/ofac/sdn/delimit/alt.pip')))
  alt.rewind
  
  if OfacSdn.connection.kind_of?(ActiveRecord::ConnectionAdapters::MysqlAdapter)
    puts "Converting file to csv format for Mysql import.  This could take several minutes."

    csv_file = convert_to_flattened_csv(sdn, address, alt)

    bulk_mysql_update(csv_file)
  else
    active_record_file_load(sdn, address, alt)
  end

  sdn.close
  @address.close
  @alt.close
end