address_tokens 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/address_tokens/version.rb +1 -1
- data/lib/matcher.rb +20 -7
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d5779cab9c82cec1bab958968a296aeb8ff2961333cb3fc6563f5375faec9c
|
4
|
+
data.tar.gz: 87ae2f37a3b28c2b1d218fc52ce84b8669d0c00394645c4324c1708dc7ca41b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa657990faf5138c8b266a26656959b9a7dd5e9e736901c6838521bac2afe9b04ea8085bf5983f9374953740524ffd512d01407be29f17418e20fb2ff8badd0
|
7
|
+
data.tar.gz: dfb7bafe985852db0236321cb97e3075ec6f22b1068c974c5633dbf632a92be6336fffe01ce5a91890d57435ede43fbf577d444d685ceb2d12d75a0cd19debc6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/matcher.rb
CHANGED
@@ -5,10 +5,10 @@ module AddressTokens
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def match(str)
|
8
|
-
|
8
|
+
zip_info = find_zip(str)
|
9
|
+
state_info = find_state(str, zip_info)
|
9
10
|
city_info = find_city(str, state_info)
|
10
|
-
address_info = find_address(str, city_info)
|
11
|
-
zip_info = find_zip(str, address_info)
|
11
|
+
address_info = remove_zip(find_address(str, city_info), zip_info)
|
12
12
|
|
13
13
|
{
|
14
14
|
state_abbr: state_info[:state],
|
@@ -25,7 +25,15 @@ module AddressTokens
|
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
def
|
28
|
+
def remove_end_zip_for_state(str, zip_info)
|
29
|
+
return str if !@finder.zip_format[:format].to_s.include?(@finder.state_separator)
|
30
|
+
return str if !zip_info
|
31
|
+
return str if !zip_info[:zip_on_end]
|
32
|
+
str.strip.sub(Regexp.new("#{zip_info[:zip_string]}\\z"), '')
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_state(str, zip_info)
|
36
|
+
str = remove_end_zip_for_state(str, zip_info)
|
29
37
|
last_char = str.rindex(@finder.state_separator)
|
30
38
|
token = str[last_char .. -1]
|
31
39
|
token = token.gsub(/\s{2,}/, ' ')
|
@@ -90,13 +98,18 @@ module AddressTokens
|
|
90
98
|
{ address: str.split(city_info[:city_string])[0].strip }
|
91
99
|
end
|
92
100
|
|
93
|
-
def find_zip(str
|
101
|
+
def find_zip(str)
|
94
102
|
matches = str.match @finder.zip_format[:format]
|
95
103
|
joiner = @finder.zip_format[:join] || [ nil ]
|
96
104
|
zip = matches ? matches[1..-1].zip(joiner).flatten.join : nil
|
97
105
|
zip_str = matches ? matches[0] : nil
|
98
|
-
|
99
|
-
|
106
|
+
{ zip: zip, zip_string: zip_str, zip_on_end: zip_str && Regexp.new("#{zip_str}\\z").match?(str) }
|
107
|
+
end
|
108
|
+
|
109
|
+
def remove_zip(address_info, zip_info)
|
110
|
+
return address_info if !address_info || !zip_info || !zip_info[:zip_string]
|
111
|
+
address_info[:address] = address_info[:address].sub(zip_info[:zip_string], '').strip
|
112
|
+
address_info
|
100
113
|
end
|
101
114
|
end
|
102
115
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: address_tokens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eustaquio Rangel
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
G+/hO8DFcpmRPCD/YXu/rFkKHquizBGSfr1BR/es/HhfrIoT3BUN2uDUT02aaWmB
|
32
32
|
JMg=
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2018-01-
|
34
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
metadata.gz.sig
CHANGED
Binary file
|