Permalink
Browse files

Add a whole bunch of stuff towards Ruby packaging.

  • Loading branch information...
1 parent 699aa60 commit 9ddaa99b2cefe7f4e4a89d95b3118e30f70202eb @schuyler schuyler committed Jun 5, 2009
Showing with 123 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +6 −0 History.txt
  3. +18 −0 Manifest.txt
  4. +48 −0 README.txt
  5. +29 −0 Rakefile
  6. +1 −1 demo/views/index.builder
  7. +16 −6 demo/ws.rb
  8. +4 −0 lib/geocoder/us.rb
View
@@ -1,5 +1,6 @@
*.o
*.so
+pkg/
bin/shp2sqlite
src/shp2sqlite/shp2sqlite
src/liblwgeom/liblwgeom.a
View
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2009-06-02
+
+* 1 major enhancement
+
+ * Birthday!
+
View
@@ -0,0 +1,18 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/geocoder/us/database.rb
+lib/geocoder/us/numbers.rb
+lib/geocoder/us/address.rb
+lib/geocoder/us/constants.rb
+tests/database.rb
+tests/numbers.rb
+tests/generate.rb
+tests/run.rb
+tests/address.rb
+tests/benchmark.rb
+tests/constants.rb
+tests/data/address-sample.csv
+tests/data/locations.csv
+tests/data/db-test.csv
View
@@ -0,0 +1,48 @@
+= geocoder_us
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2009 FIX
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,29 @@
+require 'rubygems'
+Gem::manage_gems
+require 'rake/gempackagetask'
+
+spec = Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = 'Geocoder-US'
+ s.version = "1.0.0"
+ s.author = "Schuyler Erle"
+ s.email = 'geocoder@entropyfree.com'
+ s.description = "US address geocoding based on TIGER/Line."
+ s.summary = "US address geocoding based on TIGER/Line."
+ s.homepage = "http://geocoder.us/"
+ s.files = FileList[
+ 'lib/geocoder/*.rb', 'lib/geocoder/us/*.rb', 'tests/*'].to_a
+ s.require_path = "lib"
+ s.test_files = "tests/run.rb"
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README"]
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_tar = true
+end
+
+task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
+ puts "generated latest version"
+end
+
View
@@ -3,7 +3,7 @@ xml.locations do
@records.each do |record|
xml.location do
xml.score format("%.2f", record[:score]*100)
- %w{lat lon prefix pretyp predir prequal street suftyp sufdir sufqual city state zip}.each do |field|
+ %w{lat lon number prefix pretyp predir prequal street suftyp sufdir sufqual city state zip}.each do |field|
xml.tag! field, record[field.to_sym]
end
end
View
@@ -2,12 +2,14 @@
require 'sinatra'
require 'geocoder/us/database'
require 'fastercsv'
+require 'json'
set :port, 8080
get '/' do
unless params[:address].nil?
- db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db")
+ db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db",
+ "/home/sderle/geocoder/lib/libsqlite3_geocoder.so")
@records = db.geocode params[:address]
end
@@ -54,26 +56,34 @@
post '/batch' do
+ if params.include?(:uploaded_csv)
FileUtils.mkdir_p('uploads/')
FileUtils.mv(params[:uploaded_csv][:tempfile].path, "uploads/#{params[:uploaded_csv][:filename]}")
- csv_file = "uploads/#{params[:uploaded_csv][:filename]}"
- db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db")
+ csv_file = open("uploads/#{params[:uploaded_csv][:filename]}")
@filename = params[:uploaded_csv][:filename].gsub(/\.csv/,"")
- csv = FasterCSV.parse(open(csv_file))
+ csv = FasterCSV.parse(csv_file)
+ else
+ csv_file = request.env["rack.input"].read
+ csv = FasterCSV.parse(csv_file, :row_sep => "*", :col_sep => "|")
+ end
+ db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db")
headers = csv[0]
@records = csv.collect do |record|
next if record == headers
begin
- (db.geocode record[1]).first
+ puts record[1]
+ (db.geocode record[1]).first.merge(headers[0] => record[0])
rescue Exception => e
puts e.message
next
end
end.compact
case params[:format]
- when /atom/
+ when /atom|xml/
builder :index
+ when /json/
+ @records.to_json
else
erb :index
end
View
@@ -0,0 +1,4 @@
+require "geocoder/us/database"
+require "geocoder/us/address"
+
+Geocoder::US::VERSION = "1.0.0"

0 comments on commit 9ddaa99

Please sign in to comment.