geocode_records 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/bin/geocode_records +0 -6
- data/geocode_records.gemspec +1 -0
- data/lib/geocode_records/geocode_csv.rb +5 -0
- data/lib/geocode_records/smarty_streets.rb +1 -1
- data/lib/geocode_records/version.rb +1 -1
- data/lib/geocode_records.rb +4 -2
- data/package.json +1 -1
- data/spec/geocode_records/smarty_streets_spec.rb +2 -2
- data/spec/geocode_records_spec.rb +22 -6
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cec9b1bf42ae7aa40359d9a4d84f0ab30273358
|
4
|
+
data.tar.gz: 6aa1c9fab15253fd0f16b7ba5ba12a3d73390d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 805f6cf61202f52be4078e6df883ddefc8eee9cb559742ee912fd9f5b1469f2c06de840218030f8ab1b682254dca515eaec2a5f57b66dc76b5fea00b9eeb8112
|
7
|
+
data.tar.gz: 17fbb907970b4bc2608250598366159dd5501f14568bb649c3070f5b67b27314fe8e16d1e1013de21e2539c3466a85825664e62078d9cafb2745994ed154290a
|
data/CHANGELOG
CHANGED
data/bin/geocode_records
CHANGED
@@ -6,12 +6,6 @@ require 'geocode_records'
|
|
6
6
|
|
7
7
|
ActiveRecord::Base.establish_connection ENV.fetch('DATABASE_URL')
|
8
8
|
|
9
|
-
# http://gray.fm/2013/09/17/unknown-oid-with-rails-and-postgresql/
|
10
|
-
require 'active_record/connection_adapters/postgresql/oid'
|
11
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.tap do |klass|
|
12
|
-
klass::OID.register_type('geometry', klass::OID::Identity.new)
|
13
|
-
end
|
14
|
-
|
15
9
|
logger = Logger.new($stderr)
|
16
10
|
logger.level = Logger::WARN
|
17
11
|
ActiveRecord::Base.logger = logger
|
data/geocode_records.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'activerecord', '~>4.1.9'
|
22
|
+
spec.add_runtime_dependency 'activesupport'
|
22
23
|
spec.add_runtime_dependency 'pg'
|
23
24
|
spec.add_runtime_dependency 'attr_extras'
|
24
25
|
spec.add_runtime_dependency 'zaru'
|
@@ -10,11 +10,13 @@ require 'geocode_records/smarty_streets'
|
|
10
10
|
class GeocodeRecords
|
11
11
|
class GeocodeCsv
|
12
12
|
attr_reader :glob
|
13
|
+
attr_reader :include_invalid
|
13
14
|
|
14
15
|
def initialize(input_path, options = {})
|
15
16
|
@input_path = input_path
|
16
17
|
options ||= {}
|
17
18
|
@glob = options[:glob]
|
19
|
+
@include_invalid = options[:include_invalid]
|
18
20
|
@mutex = Mutex.new
|
19
21
|
end
|
20
22
|
|
@@ -53,6 +55,9 @@ class GeocodeRecords
|
|
53
55
|
'--auth-id', ENV.fetch('SMARTY_STREETS_AUTH_ID'),
|
54
56
|
'--auth-token', ENV.fetch('SMARTY_STREETS_AUTH_TOKEN')
|
55
57
|
]
|
58
|
+
if include_invalid
|
59
|
+
args += [ '--include-invalid' ]
|
60
|
+
end
|
56
61
|
input_map.each do |ss, local|
|
57
62
|
args += [ "--#{ss}-col", local.to_s ]
|
58
63
|
end
|
data/lib/geocode_records.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'active_record'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
2
4
|
require 'attr_extras'
|
3
5
|
require 'pasqual'
|
4
6
|
|
@@ -14,7 +16,7 @@ class GeocodeRecords
|
|
14
16
|
attr_reader :options
|
15
17
|
def initialize(records, options = {})
|
16
18
|
records.is_a?(ActiveRecord::Relation) or raise(ArgumentError, "expected AR::Relation, got #{records.class}")
|
17
|
-
@options = options || {}
|
19
|
+
@options = (options || {}).symbolize_keys
|
18
20
|
@records = records
|
19
21
|
end
|
20
22
|
|
@@ -51,7 +53,7 @@ class GeocodeRecords
|
|
51
53
|
if glob
|
52
54
|
c.to_sql records.select('id', 'glob').arel, records.bind_values
|
53
55
|
else
|
54
|
-
c.to_sql records.select('id', 'house_number_and_street', 'house_number', 'unit_number', 'city', 'state', "
|
56
|
+
c.to_sql records.select('id', 'house_number_and_street', 'house_number', 'unit_number', 'city', 'state', "regexp_replace(postcode, '.0$', '') AS postcode").arel, records.bind_values
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
data/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
dbname = 'geocode_records_test'
|
4
|
-
ENV['DATABASE_URL']
|
4
|
+
ENV['DATABASE_URL'] = "postgresql://127.0.0.1/#{dbname}"
|
5
5
|
|
6
6
|
unless ENV['FAST'] == 'true'
|
7
7
|
psql = Pasqual.for ENV['DATABASE_URL']
|
@@ -43,11 +43,6 @@ end
|
|
43
43
|
|
44
44
|
require 'active_record'
|
45
45
|
ActiveRecord::Base.establish_connection
|
46
|
-
# http://gray.fm/2013/09/17/unknown-oid-with-rails-and-postgresql/
|
47
|
-
require 'active_record/connection_adapters/postgresql/oid'
|
48
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.tap do |klass|
|
49
|
-
klass::OID.register_type('geometry', klass::OID::Identity.new)
|
50
|
-
end
|
51
46
|
|
52
47
|
class Home < ActiveRecord::Base
|
53
48
|
end
|
@@ -95,6 +90,27 @@ describe GeocodeRecords do
|
|
95
90
|
expect(home.house_number_and_street).to eq('36 Main St')
|
96
91
|
end
|
97
92
|
|
93
|
+
it "doesn't break on zip-4" do
|
94
|
+
home = Home.create! house_number_and_street: '1038 e dayton st', postcode: '53703-2428'
|
95
|
+
GeocodeRecords.new(Home.all).perform
|
96
|
+
home.reload
|
97
|
+
expect(home.house_number_and_street).to eq('1038 E Dayton St')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "accepts city and state only" do
|
101
|
+
home = Home.create! house_number_and_street: '1038 e dayton st', city: 'madison', state: 'wisconsin'
|
102
|
+
GeocodeRecords.new(Home.all).perform
|
103
|
+
home.reload
|
104
|
+
expect(home.house_number_and_street).to eq('1038 E Dayton St')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "allows invalid" do
|
108
|
+
home = Home.create! house_number_and_street: '1039 e dayton st', city: 'madison', state: 'wisconsin'
|
109
|
+
GeocodeRecords.new(Home.all, include_invalid: true).perform
|
110
|
+
home.reload
|
111
|
+
expect(home.house_number_and_street).to eq('1039 E Dayton St')
|
112
|
+
end
|
113
|
+
|
98
114
|
describe 'known issues' do
|
99
115
|
it "doesn't fix float-format postcode on records that it can't geocode" do
|
100
116
|
home = Home.create! house_number_and_street: 'gibberish', postcode: '53703.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocode_records
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.1.9
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pg
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|