module Geocoder::MaxmindDatabase
Public Instance Methods
archive_filename(package)
click to toggle source
# File lib/maxmind_database.rb, line 32 def archive_filename(package) p = archive_url_path(package) s = !(pos = p.rindex('/')).nil? && pos + 1 || 0 p[s..-1] end
download(package, dir = "tmp")
click to toggle source
# File lib/maxmind_database.rb, line 8 def download(package, dir = "tmp") filepath = File.expand_path(File.join(dir, archive_filename(package))) open(filepath, 'wb') do |file| uri = URI.parse(archive_url(package)) Net::HTTP.start(uri.host, uri.port) do |http| http.request_get(uri.path) do |resp| # TODO: show progress resp.read_body do |segment| file.write(segment) end end end end end
insert(package, dir = "tmp")
click to toggle source
# File lib/maxmind_database.rb, line 23 def insert(package, dir = "tmp") data_files(package, dir).each do |filepath,table| print "Resetting table #{table}..." ActiveRecord::Base.connection.execute("DELETE FROM #{table}") puts "done" insert_into_table(table, filepath) end end