us_street 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/lib/us_street/version.rb +1 -1
- data/lib/us_street.rb +21 -16
- data/spec/us_street_spec.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c13a0e9d18bb2aaf9fc6311cae3322b3d3be582
|
4
|
+
data.tar.gz: ffaeffddf9d4237f730479c754b0374e83d23f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d91e8b113fb8e9acb1eb3598492c8d1a713dbf2ec2100264b527ddafa5e96f1879d5d710725fcc0f4bca0b4383e692b1b94ef6491c8c7ecfff8f0d61b7ccc28d
|
7
|
+
data.tar.gz: 6871c87474a63ab99591d9fbc04aa2cbfa058faf7cdc44431f5fabc049b13ee7a29d5a6a1413dcd148edde40e41ecf9809516b74fd6b15ae7214b433e13a6bb3
|
data/lib/us_street/version.rb
CHANGED
data/lib/us_street.rb
CHANGED
@@ -82,8 +82,6 @@ class UsStreet
|
|
82
82
|
sidx, eidx = 0, parts.length - 1
|
83
83
|
unit_number = dir_suffix = dir_prefix = street_suffix = street_number = road_number = nil
|
84
84
|
|
85
|
-
# start at the end and chomp
|
86
|
-
|
87
85
|
# We could have a unit number last. Format '#\d+' but it's removed by the cleaners so match the original
|
88
86
|
if match = original_full_street.match(/#(\d+)$/)
|
89
87
|
unit_number = match[1]
|
@@ -95,24 +93,31 @@ class UsStreet
|
|
95
93
|
eidx -= 1
|
96
94
|
end
|
97
95
|
|
98
|
-
#
|
99
|
-
|
100
|
-
eidx -= 1 if
|
101
|
-
|
102
|
-
#
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
sidx += 1
|
96
|
+
# strip suffixes starting at the end and working backwards
|
97
|
+
# Check for a postdirectional (directional suffix)
|
98
|
+
eidx -= 1 if eidx - sidx > 0 and dir_suffix = direction_mapping(parts[eidx])
|
99
|
+
|
100
|
+
# Check for a street suffix. If there's already a street suffix override,
|
101
|
+
# don't strip from string unless it's the same suffix.
|
102
|
+
# Otherwise "Forest Trail Rd" gets stripped to "Forest Trl"
|
103
|
+
if eidx - sidx > 0 and street_suffix_maybe = road_mapping(parts[eidx])
|
104
|
+
if overrides[:street_suffix].blank? or street_suffix_maybe == road_mapping(overrides[:street_suffix])
|
105
|
+
street_suffix = street_suffix_maybe
|
106
|
+
eidx -= 1
|
110
107
|
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# remove components from the beginning
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
# is there a street number at beginning
|
113
|
+
if eidx - sidx > 0 and parts[sidx] =~ /^\d+$/
|
114
|
+
street_number = parts[sidx]
|
115
|
+
sidx += 1
|
114
116
|
end
|
115
117
|
|
118
|
+
# is there a predirectional?
|
119
|
+
sidx += 1 if eidx - sidx > 0 and dir_prefix = direction_mapping(parts[sidx])
|
120
|
+
|
116
121
|
# fix weirdo street names and make them consistent
|
117
122
|
parts[sidx] = "St" if parts[sidx] =~ /^((st\.?)|(saint))$/i # catch "Saint John Street"
|
118
123
|
parts[sidx] = "Dr" if parts[sidx] =~ /^((dr\.?)|(doctor))$/i # catch "Dr. Oz Road"
|
data/spec/us_street_spec.rb
CHANGED
@@ -84,6 +84,12 @@ describe UsStreet do
|
|
84
84
|
us_street = UsStreet.from_attrs(" 123", 'S', "North 12th St WEST", 'Street', 'E')
|
85
85
|
expect(us_street.full_street).to eq('123 S 12th St E')
|
86
86
|
end
|
87
|
+
|
88
|
+
# yes this is a real address: 2644 E North Ln, Phoenix, AZ 85028
|
89
|
+
it "doesn't strip North if it's the full street name" do
|
90
|
+
us_street = UsStreet.from_attrs("2644", "E", "North", "Ln", nil)
|
91
|
+
expect(us_street.full_street).to eq("2644 E North Ln")
|
92
|
+
end
|
87
93
|
end
|
88
94
|
end
|
89
95
|
|
@@ -125,6 +131,11 @@ describe UsStreet do
|
|
125
131
|
expect(us_street.full_street).to eq("123 N Main Southy")
|
126
132
|
end
|
127
133
|
|
134
|
+
it "doesn't strip directions in street name" do
|
135
|
+
us_street = UsStreet.parse("2644 E North Ln")
|
136
|
+
expect(us_street.full_street).to eq("2644 E North Ln")
|
137
|
+
end
|
138
|
+
|
128
139
|
it "strips off spaces" do
|
129
140
|
us_street = UsStreet.parse(" 123 N main southy ")
|
130
141
|
expect(us_street.full_street).to eq("123 N Main Southy")
|
@@ -145,7 +156,8 @@ describe UsStreet do
|
|
145
156
|
it 'prefers an explicit street_suffix' do
|
146
157
|
us_street = UsStreet.parse("123 main southy road", street_suffix: "st")
|
147
158
|
expect(us_street.street_suffix).to eq('St')
|
148
|
-
|
159
|
+
# we can't strip Road here, it may be part of the street name in fact.
|
160
|
+
expect(us_street.full_street).to eq("123 Main Southy Road St")
|
149
161
|
end
|
150
162
|
|
151
163
|
it 'handles unit numbers' do
|
@@ -204,5 +216,13 @@ describe UsStreet do
|
|
204
216
|
expect(street.street_suffix).to eq('Rd')
|
205
217
|
expect(street.unit).to eq('12')
|
206
218
|
end
|
219
|
+
|
220
|
+
it 'doesnt strip street when overrides are present' do
|
221
|
+
street = UsStreet.parse("PALM BEACH", {:street_number=>"20127", :dir_prefix=>"E", :street_suffix=>"Drive"})
|
222
|
+
expect(street.full_street).to eq('20127 E Palm Beach Dr')
|
223
|
+
expect(street.street_number).to eq('20127')
|
224
|
+
expect(street.street_name).to eq('Palm Beach')
|
225
|
+
expect(street.street_suffix).to eq('Dr')
|
226
|
+
end
|
207
227
|
end
|
208
228
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: us_street
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Neighman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|