-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzip_codes.rb
More file actions
24 lines (20 loc) · 810 Bytes
/
zip_codes.rb
File metadata and controls
24 lines (20 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby
require 'rubygems'
require 'sqlite3'
DBFILE = File.dirname(__FILE__) + '/data/zip_codes.db'
raise "Please populate the database first" unless File.exist?(DBFILE)
begin
ZIP_DB = SQLite3::Database.open( DBFILE )
raise "No database available. Please initialize it with Rake." unless ZIP_DB.kind_of?(SQLite3::Database)
ZIP_META = ZIP_DB.execute("SELECT * FROM sqlite_master;").first.last.split(/[\r\n\t]+/)
#raise "Can't query DB" unless (ZIP_META.kind_of?(Array) && ZIP_META.include?("zip_codes"))
ZIP_COLUMNS = []
ZIP_META.each do |l|
next unless l =~ /^ ([\S]+)\s+/
ZIP_COLUMNS.push($1.to_sym)
end
rescue Exception => e
puts "There is a problem with your database: #{e.message}"
end
#raise ZIP_META.inspect
require File.dirname(__FILE__) + '/lib/zip_code.rb'