geocode_records 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edc2c231e4b2b56695ce060e5712a20f5af64b53
4
- data.tar.gz: 1aa1438ca13d54c8fcf042ada691e7d5c3c53175
3
+ metadata.gz: bfc6e01f883ce3a016471d9e3f74198bf47a341a
4
+ data.tar.gz: d48772e3d9cd635d3adf03c83871ffd3a467a6e5
5
5
  SHA512:
6
- metadata.gz: 71e2a3a9fe9d42bd815c02844c6d14cdde9599f7e6480459a2d217290b06fddeb13faf3027402e5bc222aa74de568bb09ccf56bc734f4aec4991f88b29b2101c
7
- data.tar.gz: 629c638c72442db0d31409066e9ba09917463b588c8a1117256475dcee54fd5886b1420e69342f9092ca751175b82f33570f43172e960befe3cc55d466e6d2a3
6
+ metadata.gz: 0ba48446ffa487e0195415d59955da64ef112349583033f508d78e9c4aa9c236a64e9a50394cd1afdb7abe17ef1941babfb943fbf9ee9a959168118250651092
7
+ data.tar.gz: a821dba02207e2eb881404555e7294d677309bb4a63aad4987fdf85351e62b7a37f770b2c32fe10da95e8b0e52c267d4a2381b475087dc2fcbda0a0aa3543385
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.0.4 / 2015-06-02
2
+
3
+ * Enhancements
4
+
5
+ * Depend on new fixed version of smartystreets geocoder module
6
+
1
7
  0.0.3 / 2015-03-27
2
8
 
3
9
  * Enhancements
@@ -6,6 +6,7 @@ require_relative 'geocode_records/version'
6
6
  require_relative 'geocode_records/dump_sql_to_csv'
7
7
  require_relative 'geocode_records/geocode_csv'
8
8
  require_relative 'geocode_records/update_table_from_csv'
9
+ require_relative 'geocode_records/smarty_streets'
9
10
 
10
11
  class GeocodeRecords
11
12
 
@@ -18,6 +19,8 @@ class GeocodeRecords
18
19
  end
19
20
 
20
21
  def perform
22
+ raise "smartystreets >= 1.5.0 is required" unless SmartyStreets.compatible?
23
+
21
24
  if records.count > 0
22
25
  # $stderr.puts "GeocodeRecords: #{records.count} to go!"
23
26
  ungeocoded_path = DumpSqlToCsv.new(pasqual, to_sql, options).path
@@ -4,6 +4,8 @@ require 'csv'
4
4
  require 'shellwords'
5
5
  require 'zaru'
6
6
 
7
+ require 'geocode_records/smarty_streets'
8
+
7
9
  # copied from hotdog/app/services/file_geocoder.rb with seamus variations
8
10
  class GeocodeRecords
9
11
  class GeocodeCsv
@@ -46,7 +48,6 @@ class GeocodeRecords
46
48
  def geocode
47
49
  @geocoded_path = Dir::Tmpname.create(Zaru.sanitize!(input_path + '.geocode')) {}
48
50
  args = [
49
- smartystreets_bin_path,
50
51
  '-i', input_path,
51
52
  '-o', geocoded_path,
52
53
  '--auth-id', ENV.fetch('SMARTY_STREETS_AUTH_ID'),
@@ -55,8 +56,7 @@ class GeocodeRecords
55
56
  input_map.each do |ss, local|
56
57
  args += [ "--#{ss}-col", local.to_s ]
57
58
  end
58
- puts Shellwords.join(args)
59
- system(*args)
59
+ SmartyStreets.run *args
60
60
  raise "Geocoding failed on #{input_path.inspect} with args #{Shellwords.join(args)}" unless $?.success?
61
61
  end
62
62
 
@@ -92,21 +92,5 @@ class GeocodeRecords
92
92
  RECODE_MAP[output_k] || output_k
93
93
  end
94
94
  end
95
-
96
- def smartystreets_bin_path
97
- @smartystreets_bin_path ||= begin
98
- memo = if File.exist?('node_modules/.bin/smartystreets')
99
- 'node_modules/.bin/smartystreets'
100
- else
101
- 'smartystreets'
102
- end
103
- `#{memo} -V` =~ /\A(\d+)\.(\d+)\.(\d+)/
104
- major, minor, patch = [$1, $2, $3].map(&:to_i)
105
- unless major >= 1 and minor >= 3 and patch >= 2
106
- raise "smartystreets >= 1.3.2 required, got #{major}.#{minor}.#{patch}"
107
- end
108
- memo
109
- end
110
- end
111
95
  end
112
96
  end
@@ -0,0 +1,32 @@
1
+ class GeocodeRecords
2
+
3
+ module SmartyStreets
4
+
5
+ def self.bin_path
6
+ @bin_path ||= if File.exist?('node_modules/.bin/smartystreets')
7
+ 'node_modules/.bin/smartystreets'
8
+ else
9
+ 'smartystreets'
10
+ end
11
+ end
12
+
13
+ def self.compatible?
14
+ output = run_with_output('-V')
15
+ current_version = Gem::Version.new output.chomp
16
+ min_version = Gem::Version.new '1.5.0'
17
+ current_version >= min_version
18
+ end
19
+
20
+ def self.run(*args)
21
+ shargs = Shellwords.join(args)
22
+ system "#{bin_path} #{shargs}"
23
+ end
24
+
25
+ def self.run_with_output(*args)
26
+ shargs = Shellwords.join(args)
27
+ `#{bin_path} #{shargs}`
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -1,3 +1,3 @@
1
1
  class GeocodeRecords
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/package.json CHANGED
@@ -2,6 +2,6 @@
2
2
  "name": "rolodeck",
3
3
  "private": true,
4
4
  "dependencies": {
5
- "smartystreets": "^1.3.2"
5
+ "smartystreets": "^1.5.0"
6
6
  }
7
7
  }
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ require 'geocode_records/smarty_streets'
4
+
5
+ describe GeocodeRecords::SmartyStreets do
6
+
7
+ describe '.bin_path' do
8
+ subject { described_class.bin_path }
9
+
10
+ it { is_expected.to eq 'node_modules/.bin/smartystreets' }
11
+ end
12
+
13
+ describe '.compatible?' do
14
+ before { allow(described_class).to receive(:run_with_output).and_return("#{version}\n") }
15
+
16
+ subject { described_class.compatible? }
17
+
18
+ context 'v1.3.1' do
19
+ let(:version) { '1.3.1' }
20
+
21
+ it { is_expected.to be false }
22
+ end
23
+
24
+ context 'v1.3.2' do
25
+ let(:version) { '1.3.2' }
26
+
27
+ it { is_expected.to be false }
28
+ end
29
+
30
+ context 'v1.5.0' do
31
+ let(:version) { '1.5.0' }
32
+
33
+ it { is_expected.to be true }
34
+ end
35
+
36
+ end
37
+
38
+ describe '.run_with_output' do
39
+ subject { described_class.run_with_output '-V' }
40
+
41
+ it { is_expected.to match /\d+\.\d+.\d+/ }
42
+ end
43
+
44
+ end
45
+
@@ -1,13 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  dbname = 'geocode_records_test'
4
- ENV['DATABASE_URL'] = "postgresql://127.0.0.1/#{dbname}"
4
+ ENV['DATABASE_URL'] ||= "postgresql://127.0.0.1/#{dbname}"
5
5
 
6
6
  unless ENV['FAST'] == 'true'
7
- system 'dropdb', '--if-exists', dbname
8
- system 'createdb', dbname
9
- system 'psql', dbname, '--command', 'CREATE EXTENSION postgis'
10
- system 'psql', dbname, '--command', 'CREATE TABLE homes (id serial primary key, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857), house_number_and_street text, house_number int, unit_number text, city text, state text, postcode text, latitude float, longitude float)'
7
+ psql = Pasqual.for ENV['DATABASE_URL']
8
+ psql.dropdb rescue nil
9
+ psql.createdb
10
+ psql.command 'CREATE EXTENSION postgis'
11
+ psql.command <<-SQL
12
+ CREATE TABLE homes (
13
+ id serial primary key,
14
+ the_geom geometry(Geometry,4326),
15
+ the_geom_webmercator geometry(Geometry,3857),
16
+ house_number_and_street text,
17
+ house_number int,
18
+ unit_number text,
19
+ city text,
20
+ state text,
21
+ postcode text,
22
+ latitude float,
23
+ longitude float
24
+ )
25
+ SQL
11
26
  end
12
27
 
13
28
  require 'active_record'
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -157,9 +157,11 @@ files:
157
157
  - lib/geocode_records.rb
158
158
  - lib/geocode_records/dump_sql_to_csv.rb
159
159
  - lib/geocode_records/geocode_csv.rb
160
+ - lib/geocode_records/smarty_streets.rb
160
161
  - lib/geocode_records/update_table_from_csv.rb
161
162
  - lib/geocode_records/version.rb
162
163
  - package.json
164
+ - spec/geocode_records/smarty_streets_spec.rb
163
165
  - spec/geocode_records_spec.rb
164
166
  - spec/spec_helper.rb
165
167
  homepage: https://github.com/seamusabshere/geocode_records
@@ -187,5 +189,7 @@ signing_key:
187
189
  specification_version: 4
188
190
  summary: Geocode an ActiveRecord::Relation with node_smartystreets
189
191
  test_files:
192
+ - spec/geocode_records/smarty_streets_spec.rb
190
193
  - spec/geocode_records_spec.rb
191
194
  - spec/spec_helper.rb
195
+ has_rdoc: