address-matcher 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d2d27af283ba186e00ff6ddbb3055b509b8e0b4
4
- data.tar.gz: 5ceafeb2391eb02c0b3b037f5142f4b8e6082024
3
+ metadata.gz: a5ad7065d7364b08e5790c9a167dfd7cf8ac4f2b
4
+ data.tar.gz: d45880a4f355aa72a7e60f32eb751073fea926d5
5
5
  SHA512:
6
- metadata.gz: 106dc2f97921d4cf2c5a0d19a815574477ca537106bad49e2cd67eb03ae7e75411a96ad91f21e4f77e1e6e2d6f637e8e9724c94983d8271c7200466e1b5b25a2
7
- data.tar.gz: a0b5921cb6120bfae41c0e630c813fee91f28d968b4f3049f1f2280a2a401306be8faa1b0308b5f2bcf797e6a9195c04f470925e7495730214a9ce2b642f0d22
6
+ metadata.gz: 4c22c19bbf32d8695713f82741f90c3d43b49c5f08324dc818da039e3fd5433997503cab82e1912f5f65c7683507ab05a63a9513d03409d0ddc39f766dda48cc
7
+ data.tar.gz: ab353263bf9c8223dbcce9ca2c504b3b0cdff1571d2bfd2a3d2f95ee06033d741246131f1d8b8878787c060a60801ac177d2118164aaf365c911afb765ecf111
data/README.md CHANGED
@@ -10,9 +10,9 @@ if they are close enough.
10
10
 
11
11
  ## Usage
12
12
 
13
- `$ gem install address_matcher`
13
+ `$ gem install address-matcher`
14
14
 
15
- `require address_matcher`
15
+ `require address-matcher`
16
16
 
17
17
  Create an `AddressLibrary` with all of the "known" address strings that you want
18
18
  to match against:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'address-matcher'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2015-04-07'
5
5
  s.summary = "Matches addresses by geocoding"
6
6
  s.description = "Uses geocoding to perform fuzzy match on address strings"
@@ -15,7 +15,9 @@ class AddressLibrary
15
15
 
16
16
  def add_address(address_string)
17
17
  coords = geocode(address_string)
18
- store[latitude_index(coords)][longitude_index(coords)][coords] = address_string
18
+ if coords
19
+ store[latitude_index(coords)][longitude_index(coords)][coords] = address_string
20
+ end
19
21
  self
20
22
  end
21
23
 
@@ -25,17 +27,20 @@ class AddressLibrary
25
27
 
26
28
  def match(address_string)
27
29
  coords = geocode(address_string)
28
- group = store[latitude_index(coords)][longitude_index(coords)]
29
- group.match(coords)
30
+ if coords
31
+ group = store[latitude_index(coords)][longitude_index(coords)]
32
+ group.match(coords)
33
+ end
30
34
  end
31
35
 
32
36
  private
33
37
  attr_reader :store
34
38
 
35
39
  def geocode(address_string)
36
- Geocoder.search(address_string)
37
- .first
38
- .coordinates
40
+ response = Geocoder.search(address_string).first
41
+ if response
42
+ response.coordinates
43
+ end
39
44
  end
40
45
 
41
46
  def latitude_index(coords)
@@ -24,6 +24,12 @@ describe AddressLibrary do
24
24
  )
25
25
  end
26
26
 
27
+ it 'does not add an address if the geocode does not return coordinates' do
28
+ expect do
29
+ AddressLibrary.new.add_address(not_found.address)
30
+ end.not_to raise_error
31
+ end
32
+
27
33
  it 'adds multiple nearby addresses to the same AddressGroup' do
28
34
  lib = AddressLibrary.new
29
35
  .add_address(met_art_avenue.address)
@@ -120,5 +126,21 @@ describe AddressLibrary do
120
126
  expect(match_1).to eq met_art_ave.address
121
127
  expect(match_2).to eq met_opera_short.address
122
128
  end
129
+
130
+ it 'returns nil if there are no addresses near enough to match' do
131
+ lib = AddressLibrary.new.add_address(met_opera_short.address)
132
+
133
+ match = lib.match(boco.address)
134
+
135
+ expect(match).to be_nil
136
+ end
137
+
138
+ it 'returns nil if the address cannot geocode' do
139
+ lib = AddressLibrary.new.add_address(met_opera_short.address)
140
+
141
+ match = lib.match(not_found.address)
142
+
143
+ expect(match).to be_nil
144
+ end
123
145
  end
124
146
  end
@@ -9,6 +9,10 @@ module Locations
9
9
  OpenStruct.new(data.merge(coords: [data['latitude'], data['longitude']]))
10
10
  end
11
11
  end
12
+
13
+ define_method :not_found do
14
+ OpenStruct.new(address: '123 Main St. Mars')
15
+ end
12
16
  end
13
17
 
14
18
  Locations::TEST_DATA.values.each do |location|
@@ -25,3 +29,5 @@ Locations::TEST_DATA.values.each do |location|
25
29
  ]
26
30
  )
27
31
  end
32
+
33
+ Geocoder::Lookup::Test.add_stub('123 Main St. Mars', [])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: address-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Terrett