address-matcher 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -1
- data/address_matcher.gemspec +1 -1
- data/lib/address_matcher/address_library.rb +11 -6
- data/spec/address_library_spec.rb +22 -0
- data/spec/support/geocoder.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5ad7065d7364b08e5790c9a167dfd7cf8ac4f2b
|
4
|
+
data.tar.gz: d45880a4f355aa72a7e60f32eb751073fea926d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
13
|
+
`$ gem install address-matcher`
|
14
14
|
|
15
|
-
`require
|
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.
|
1
|
+
0.1.1
|
data/address_matcher.gemspec
CHANGED
@@ -15,7 +15,9 @@ class AddressLibrary
|
|
15
15
|
|
16
16
|
def add_address(address_string)
|
17
17
|
coords = geocode(address_string)
|
18
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
38
|
-
|
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
|
data/spec/support/geocoder.rb
CHANGED
@@ -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', [])
|