class TelephoneNumber::GeoLocationDataImporter

Public Class Methods

load_data!() click to toggle source
# File lib/importers/geo_location_data_importer.rb, line 3
def self.load_data!
  Dir.glob("data/geocoding/**/*.txt").each { |file| process_file(file) }
end
process_file(file_path) click to toggle source
# File lib/importers/geo_location_data_importer.rb, line 7
def self.process_file(file_path)
  master_data = {}
  bin_file_path = "#{File.dirname(file_path)}/#{File.basename(file_path, '.txt')}.dat"

  File.open(file_path, 'r:UTF-8').each do |row|
    next if row.strip !~ /^[0-9]/
    number, location = row.split('|')
    master_data[number.strip] = location.strip
  end

  File.open(bin_file_path, 'wb'){ |file| file << Marshal.dump(master_data) }
end