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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 338481474df19c95270ab38dfd42eb10d1ecb4876535f85699502f456ee095b5
4
- data.tar.gz: a10bde1104104a40b903753d9ba43c1582ad02bb9921ce2317213b5a7853539b
3
+ metadata.gz: 27d5779cab9c82cec1bab958968a296aeb8ff2961333cb3fc6563f5375faec9c
4
+ data.tar.gz: 87ae2f37a3b28c2b1d218fc52ce84b8669d0c00394645c4324c1708dc7ca41b5
5
5
  SHA512:
6
- metadata.gz: 944a77b2f05ae96f67907a621979f8ecaced9a4d72362cad3f1a8ec7b972e59585c7b76edb361aaf2728561b973cb2b03fca8c2e1fae19677b3aaf9971c2fbb9
7
- data.tar.gz: 0f9ae18a90d8925fda0d1203e50cbaab276037b2f65f2664e83e6587d60a2f620c667df597b352e0295d25089045b9cab2960d573d28f3520cd94746b56e247a
6
+ metadata.gz: daa657990faf5138c8b266a26656959b9a7dd5e9e736901c6838521bac2afe9b04ea8085bf5983f9374953740524ffd512d01407be29f17418e20fb2ff8badd0
7
+ data.tar.gz: dfb7bafe985852db0236321cb97e3075ec6f22b1068c974c5633dbf632a92be6336fffe01ce5a91890d57435ede43fbf577d444d685ceb2d12d75a0cd19debc6
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module AddressTokens
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
data/lib/matcher.rb CHANGED
@@ -5,10 +5,10 @@ module AddressTokens
5
5
  end
6
6
 
7
7
  def match(str)
8
- state_info = find_state(str)
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 find_state(str)
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, address_info)
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
- address_info[:address] = address_info[:address].sub(zip_str, '').strip if zip_str && address_info
99
- { zip: zip, zip_string: zip_str }
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.8
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-09 00:00:00.000000000 Z
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