address_tokens 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/README.md +12 -9
- data/lib/address_tokens/version.rb +1 -1
- data/lib/finder.rb +3 -2
- data/lib/matcher.rb +13 -1
- data/lib/zip.rb +6 -0
- data.tar.gz.sig +3 -1
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 338481474df19c95270ab38dfd42eb10d1ecb4876535f85699502f456ee095b5
|
4
|
+
data.tar.gz: a10bde1104104a40b903753d9ba43c1582ad02bb9921ce2317213b5a7853539b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 944a77b2f05ae96f67907a621979f8ecaced9a4d72362cad3f1a8ec7b972e59585c7b76edb361aaf2728561b973cb2b03fca8c2e1fae19677b3aaf9971c2fbb9
|
7
|
+
data.tar.gz: 0f9ae18a90d8925fda0d1203e50cbaab276037b2f65f2664e83e6587d60a2f620c667df597b352e0295d25089045b9cab2960d573d28f3520cd94746b56e247a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -69,7 +69,6 @@ Load the cities and states:
|
|
69
69
|
```ruby
|
70
70
|
finder.load(:states, '/tmp/states.yml')
|
71
71
|
finder.load(:cities, '/tmp/cities.yml')
|
72
|
-
finder.find
|
73
72
|
```
|
74
73
|
|
75
74
|
And ask to find:
|
@@ -81,7 +80,6 @@ matches = finder.find
|
|
81
80
|
We'll get something like this:
|
82
81
|
|
83
82
|
```ruby
|
84
|
-
p matches
|
85
83
|
{
|
86
84
|
:state_abbr => "CA",
|
87
85
|
:state_name => "California",
|
@@ -89,11 +87,14 @@ p matches
|
|
89
87
|
:city_name => "San Francisco",
|
90
88
|
:city_string => "San Francisco",
|
91
89
|
:city_start_at => 23,
|
92
|
-
:address => "88 Colin P Kelly Jr St"
|
90
|
+
:address => "88 Colin P Kelly Jr St",
|
91
|
+
:zipcode => "94107",
|
92
|
+
:zipcode_string => "94107"
|
93
93
|
}
|
94
94
|
```
|
95
|
-
|
96
|
-
|
95
|
+
|
96
|
+
The `start_at` values shows where the strings were found. The `*_string` methods
|
97
|
+
shows the way the strings were originally found.
|
97
98
|
|
98
99
|
We can use the `find` method with an already instance of the `Finder` object
|
99
100
|
sending a string to it:
|
@@ -106,17 +107,17 @@ finder.find('my other string New York, Ny')
|
|
106
107
|
|
107
108
|
As we saw, the default city and states separator on USA is a comma (','), but on
|
108
109
|
Brasil is a hyphen ('-'), so, **before asking to find the address**, we must
|
109
|
-
change it:
|
110
|
+
change it. The zipcode format is also different:
|
110
111
|
|
111
112
|
```ruby
|
112
113
|
finder.state_separator = '-'
|
114
|
+
finder.zip_format = AddressTokens::Zip::BR
|
113
115
|
```
|
114
116
|
|
115
117
|
Using a Brazilian address:
|
116
118
|
|
117
119
|
```ruby
|
118
|
-
finder = AddressTokens::Finder.new('Rua Tratado de Tordesihas, 88, Pq. Estoril,
|
119
|
-
S. J. do Rio Preto - SP')
|
120
|
+
finder = AddressTokens::Finder.new('Rua Tratado de Tordesihas, 88, Pq. Estoril, 15085-110 S. J. do Rio Preto - SP')
|
120
121
|
finder.state_separator = '-'
|
121
122
|
finder.load(:states, '/tmp/states.yml')
|
122
123
|
finder.load(:cities, '/tmp/cities.yml')
|
@@ -133,7 +134,9 @@ will return:
|
|
133
134
|
:city_name => "São José do Rio Preto",
|
134
135
|
:city_string => "S. J. do Rio Preto",
|
135
136
|
:city_start_at => 44,
|
136
|
-
:address => "Rua Tratado de Tordesihas, 88, Pq. Estoril,"
|
137
|
+
:address => "Rua Tratado de Tordesihas, 88, Pq. Estoril,",
|
138
|
+
:zipcode => "15085-110",
|
139
|
+
:zipcode_string => "15085-110"
|
137
140
|
}
|
138
141
|
```
|
139
142
|
|
data/lib/finder.rb
CHANGED
@@ -3,13 +3,14 @@ require 'i18n'
|
|
3
3
|
|
4
4
|
module AddressTokens
|
5
5
|
class Finder
|
6
|
-
attr_accessor :states, :cities, :state_separator, :string
|
6
|
+
attr_accessor :states, :cities, :state_separator, :string, :zip_format
|
7
7
|
attr_reader :city_tokens
|
8
8
|
|
9
9
|
def initialize(str = nil)
|
10
|
-
@string, @states, @cities, = str, {}, {}
|
11
10
|
I18n.config.available_locales = :en
|
11
|
+
@string, @states, @cities, = str, {}, {}
|
12
12
|
@state_separator = ','
|
13
|
+
@zip_format = Zip::US
|
13
14
|
end
|
14
15
|
|
15
16
|
def load(var, file)
|
data/lib/matcher.rb
CHANGED
@@ -8,6 +8,7 @@ module AddressTokens
|
|
8
8
|
state_info = find_state(str)
|
9
9
|
city_info = find_city(str, state_info)
|
10
10
|
address_info = find_address(str, city_info)
|
11
|
+
zip_info = find_zip(str, address_info)
|
11
12
|
|
12
13
|
{
|
13
14
|
state_abbr: state_info[:state],
|
@@ -16,7 +17,9 @@ module AddressTokens
|
|
16
17
|
city_name: city_info[:city_name],
|
17
18
|
city_string: city_info[:city_string],
|
18
19
|
city_start_at: city_info[:start_at],
|
19
|
-
address: address_info[:address]
|
20
|
+
address: address_info[:address],
|
21
|
+
zipcode: zip_info[:zip],
|
22
|
+
zipcode_string: zip_info[:zip_string]
|
20
23
|
}
|
21
24
|
end
|
22
25
|
|
@@ -86,5 +89,14 @@ module AddressTokens
|
|
86
89
|
return { address: str[0 ... city_info[:start_at]].strip } if city_info[:start_at] > 0
|
87
90
|
{ address: str.split(city_info[:city_string])[0].strip }
|
88
91
|
end
|
92
|
+
|
93
|
+
def find_zip(str, address_info)
|
94
|
+
matches = str.match @finder.zip_format[:format]
|
95
|
+
joiner = @finder.zip_format[:join] || [ nil ]
|
96
|
+
zip = matches ? matches[1..-1].zip(joiner).flatten.join : nil
|
97
|
+
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 }
|
100
|
+
end
|
89
101
|
end
|
90
102
|
end
|
data/lib/zip.rb
ADDED
data.tar.gz.sig
CHANGED
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eustaquio Rangel
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/finder.rb
|
113
113
|
- lib/matcher.rb
|
114
114
|
- lib/state_not_found.rb
|
115
|
+
- lib/zip.rb
|
115
116
|
homepage: http://github.com/taq/address_tokens
|
116
117
|
licenses: []
|
117
118
|
metadata: {}
|
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
version: '0'
|
132
133
|
requirements: []
|
133
134
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.7.3
|
135
136
|
signing_key:
|
136
137
|
specification_version: 4
|
137
138
|
summary: Find address tokens on a string
|
metadata.gz.sig
CHANGED
Binary file
|