HornsAndHooves-indirizzo 0.1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/HornsAndHooves-indirizzo.gemspec +28 -0
- data/LICENSE.txt +165 -0
- data/README.md +87 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/indirizzo.rb +1 -0
- data/lib/indirizzo/address.rb +86 -0
- data/lib/indirizzo/address_hash_extractor.rb +85 -0
- data/lib/indirizzo/city.rb +17 -0
- data/lib/indirizzo/constants.rb +653 -0
- data/lib/indirizzo/helper.rb +30 -0
- data/lib/indirizzo/match.rb +13 -0
- data/lib/indirizzo/number_helper.rb +29 -0
- data/lib/indirizzo/numbers.rb +55 -0
- data/lib/indirizzo/parser.rb +111 -0
- data/lib/indirizzo/street.rb +40 -0
- data/test/test_address.rb +299 -0
- data/test/test_constants.rb +55 -0
- data/test/test_helper.rb +3 -0
- data/test/test_number_helper.rb +10 -0
- data/test/test_numbers.rb +44 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10bcff69dd27120f3b6d732b5ab922419017a0066dad847b57ff522ad28dd80d
|
4
|
+
data.tar.gz: efb5b857e6db651e1fbd88e6d4fe329eefd432771239e61cc657772020bb5090
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aaa962f3c611ac85823e16d47ad7e2050f8107aafa13e0e8aaa192252a6c2feefcd58e3baec384e1a97114272b905c8da149c299d5ea28a5b76a5bfcd88d73e2
|
7
|
+
data.tar.gz: 200c00d0f2221b40ab636f3955fe50311e4f48ec66d4b4455fb682dbbf0520d5cb5470cb3fa17446fd47a5b2b9d4b1678c797e6426dfe31dbe8da88cbe54cad7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{HornsAndHooves-indirizzo}
|
3
|
+
s.version = "0.1.7.1"
|
4
|
+
|
5
|
+
s.authors = [%q{Zach Belzer}, %q{Bruce Burdick}, %q{Dave Worth}]
|
6
|
+
s.date = %q{2012-01-29}
|
7
|
+
s.description = %q{Indirizzo is simply an extraction of the US Street Address parsing code from Geocoder::US}
|
8
|
+
s.email = [%q{zach@integracredit.com}, %q{rubygems.org@bruceburdick.com}, %q{dave@highgroove.com}]
|
9
|
+
|
10
|
+
s.homepage = %q{http://github.com/HornsAndHooves/indirizzo}
|
11
|
+
s.licenses = [%q{LGPL}]
|
12
|
+
s.require_paths = [%q{lib}]
|
13
|
+
s.rubygems_version = %q{1.9.2}
|
14
|
+
s.summary = %q{Indirizzo is simply an extraction of the US Street Address parsing code from Geocoder::US}
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.extra_rdoc_files = [
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.md"
|
23
|
+
]
|
24
|
+
|
25
|
+
s.add_development_dependency('rake')
|
26
|
+
s.add_development_dependency('cover_me')
|
27
|
+
s.add_development_dependency('awesome_print')
|
28
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
Indirizzo is a simple extraction of the Address class (along with the numbers
|
4
|
+
and constants handling code) from [Geocommons](http://geocommons.com/)'
|
5
|
+
[Geocoder::US 2.0](https://github.com/geocommons/geocoder) gem.
|
6
|
+
|
7
|
+
[![Build Status](https://secure.travis-ci.org/daveworth/Indirizzo.png)](http://travis-ci.org/daveworth/Indirizzo)
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/Indirizzo.png)](http://badge.fury.io/rb/Indirizzo)
|
9
|
+
|
10
|
+
## Background
|
11
|
+
|
12
|
+
My motivation for creating this extraction is the dearth of high-quality,
|
13
|
+
flexible, street address parsing gems available to the Ruby community. After
|
14
|
+
digging into Ruby-Toolbox looking for alternatives I came up with tools based on
|
15
|
+
the Perl
|
16
|
+
[GEO::StreetAddress::US](http://search.cpan.org/~sderle/Geo-StreetAddress-US-0.99/US.pm)
|
17
|
+
such as [street\_address](https://github.com/astevens/street_address). The
|
18
|
+
street_address gem ended up being much to restrictive for my needs and my
|
19
|
+
continued searching brought me to the Geocoder::US gem. Regrettably the
|
20
|
+
constraints of needing a SQLite3 database for proper geocoding added overhead to
|
21
|
+
my simple needs. I simply need to parse addresses that may, or may not, be
|
22
|
+
"complete" or "well-formed". Thus Indirizzo was born.
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
In your Gemfile, add:
|
26
|
+
|
27
|
+
```
|
28
|
+
gem "HornsAndHooves-indirizzo", require: "indirizzo"
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'indirizzo'
|
36
|
+
Indirizzo::Address.new("some address")
|
37
|
+
```
|
38
|
+
|
39
|
+
### Options
|
40
|
+
|
41
|
+
`#new` takes a string or a (pre-parsed address) hash as its first parameter and
|
42
|
+
an options hash.
|
43
|
+
|
44
|
+
In the case of a string specifying and address, Indirizzo will do its best to
|
45
|
+
parse any matter of string, though results can be complicated. In the cases
|
46
|
+
where things are complicated the various attributes in Indirizzo do their best
|
47
|
+
to keep all reasonable answers in an array which you can inspect. (ex: "1600
|
48
|
+
Pensylvania Washington", in this case the state is difficult to determine so
|
49
|
+
both "Pennsylvania" and "Washington" are returned for City and Street)
|
50
|
+
|
51
|
+
In the case of the pre-parsed address hash the keys of the
|
52
|
+
hash be symbols matching the various Address fields in Indirizzo (specifically
|
53
|
+
`:prenum`, :`number`, `:sufnum`, `:street`, `:city`, `:state`, `:zip`, `:plus4`,
|
54
|
+
and `:country`)
|
55
|
+
|
56
|
+
Currently only one option is supported for the option hash:
|
57
|
+
|
58
|
+
* `:expand_streets` - a boolean which determines if "1 First St"'s street parameter
|
59
|
+
is expanded into "1 st", "first st", and "one st" or simply left as "first st"
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
Indirizzo is a direct derivative of [Geocoder::US 2.0](https://github.com/geocommons/geocoder)
|
64
|
+
|
65
|
+
Geocoder::US 2.0 was based on earlier work by Schuyler Erle on
|
66
|
+
a Perl module of the same name. You can find it at
|
67
|
+
[http://search.cpan.org/~sderle/](http://search.cpan.org/~sderle/).
|
68
|
+
|
69
|
+
Geocoder::US 2.0 was written by Schuyler Erle, of Entropy Free LLC,
|
70
|
+
with the gracious support of FortiusOne, Inc. Please send bug reports,
|
71
|
+
patches, kudos, etc. to patches at geocoder.us.
|
72
|
+
|
73
|
+
Copyright (c) 2009 FortiusOne, Inc.
|
74
|
+
|
75
|
+
This program is free software: you can redistribute it and/or modify
|
76
|
+
it under the terms of the GNU General Public License as published by
|
77
|
+
the Free Software Foundation, either version 3 of the License, or
|
78
|
+
(at your option) any later version.
|
79
|
+
|
80
|
+
This program is distributed in the hope that it will be useful,
|
81
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
82
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
83
|
+
GNU General Public License for more details.
|
84
|
+
|
85
|
+
You should have received a copy of the GNU General Public License
|
86
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
87
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
Rake::TestTask.new(:test) do |test|
|
14
|
+
test.libs << 'lib' << 'test'
|
15
|
+
test.pattern = 'test/**/test_*.rb'
|
16
|
+
test.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/indirizzo.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'indirizzo/address'
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'indirizzo/constants'
|
2
|
+
require 'indirizzo/parser'
|
3
|
+
require 'indirizzo/address_hash_extractor'
|
4
|
+
require 'indirizzo/match'
|
5
|
+
require 'indirizzo/city'
|
6
|
+
require 'indirizzo/street'
|
7
|
+
require 'indirizzo/helper'
|
8
|
+
|
9
|
+
module Indirizzo
|
10
|
+
# The Address class takes a US street address or place name and
|
11
|
+
# constructs a list of possible structured parses of the address
|
12
|
+
# string.
|
13
|
+
class Address
|
14
|
+
attr_accessor :text
|
15
|
+
attr_accessor :prenum, :number, :sufnum
|
16
|
+
attr_accessor :street
|
17
|
+
attr_accessor :city
|
18
|
+
attr_accessor :state
|
19
|
+
attr_accessor :zip, :plus4
|
20
|
+
attr_accessor :country
|
21
|
+
attr_accessor :options
|
22
|
+
|
23
|
+
# Takes an address or place name string as its sole argument.
|
24
|
+
def initialize (text, options={})
|
25
|
+
@options = {:expand_streets => true}.merge(options)
|
26
|
+
|
27
|
+
raise ArgumentError, "no text provided" unless text and !text.empty?
|
28
|
+
if text.class == Hash
|
29
|
+
@text = ""
|
30
|
+
assign_text_to_address text
|
31
|
+
else
|
32
|
+
@text = clean text
|
33
|
+
parse
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Removes any characters that aren't strictly part of an address string.
|
38
|
+
def clean (value)
|
39
|
+
Helper.clean(value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def assign_text_to_address(text)
|
43
|
+
@text, @city, @street, @number, @prenum, @sufnum, @full_state, @state, @zip, @plus4, @country = AddressHashExtractor.extract(text, @options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def expand_numbers (string)
|
47
|
+
NumberHelper.expand_numbers(string)
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse
|
51
|
+
@city, @street, @number, @prenum, @sufnum, @full_state, @state, @zip, @plus4, @country = Parser.new(@text, @options).parse
|
52
|
+
end
|
53
|
+
|
54
|
+
def expand_streets(street)
|
55
|
+
Street.expand(street)
|
56
|
+
end
|
57
|
+
|
58
|
+
def street_parts
|
59
|
+
Street.parts(@street, @number)
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove_noise_words(strings)
|
63
|
+
Helper.remove_noise_words(strings)
|
64
|
+
end
|
65
|
+
|
66
|
+
def city_parts
|
67
|
+
City.city_parts(@city)
|
68
|
+
end
|
69
|
+
|
70
|
+
def city= (strings)
|
71
|
+
# NOTE: This will still fail on: 100 Broome St, 33333 (if 33333 is
|
72
|
+
# Broome, MT or what)
|
73
|
+
strings = expand_streets(strings) # fix for "Mountain View" -> "Mountain Vw"
|
74
|
+
match = Regexp.new('\s*\b(?:' + strings.join("|") + ')\b\s*$', Regexp::IGNORECASE)
|
75
|
+
@street = @street.map {|string| string.gsub(match, '')}.select {|s|!s.empty?}
|
76
|
+
end
|
77
|
+
|
78
|
+
def po_box?
|
79
|
+
!Match[:po_box].match(@text).nil?
|
80
|
+
end
|
81
|
+
|
82
|
+
def intersection?
|
83
|
+
!Match[:at].match(@text).nil?
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Indirizzo
|
2
|
+
class AddressHashExtractor
|
3
|
+
def self.extract(address_hash, options)
|
4
|
+
AddressHashExtractor.new(address_hash, options).extract
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(address_hash, options={})
|
8
|
+
@address_hash = address_hash
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
attr_accessor :address_hash
|
12
|
+
|
13
|
+
def extract
|
14
|
+
if !address_hash[:address].nil?
|
15
|
+
@text = Helper.clean address_hash[:address]
|
16
|
+
return Parser.new(@text, @options).parse
|
17
|
+
else
|
18
|
+
handle_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
return @text, @city, @street, @number, @prenum, @sufnum, @full_state, @state, @zip, @plus4, @country
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def handle_hash
|
26
|
+
handle_street_and_numbers
|
27
|
+
handle_city
|
28
|
+
handle_state
|
29
|
+
handle_zip
|
30
|
+
end
|
31
|
+
|
32
|
+
def handle_street_and_numbers
|
33
|
+
@street = []
|
34
|
+
@prenum = address_hash[:prenum]
|
35
|
+
@sufnum = address_hash[:sufnum]
|
36
|
+
if !address_hash[:street].nil?
|
37
|
+
@street = address_hash[:street].scan(Match[:street])
|
38
|
+
end
|
39
|
+
@number = ""
|
40
|
+
if !@street.nil?
|
41
|
+
if address_hash[:number].nil?
|
42
|
+
@street.map! { |single_street|
|
43
|
+
single_street.downcase!
|
44
|
+
@number = single_street.scan(Match[:number])[0].reject{|n| n.nil? || n.empty?}.first.to_s
|
45
|
+
single_street.sub! @number, ""
|
46
|
+
single_street.sub! /^\s*,?\s*/o, ""
|
47
|
+
}
|
48
|
+
else
|
49
|
+
@number = address_hash[:number].to_s
|
50
|
+
end
|
51
|
+
@street = Street.expand(@street) if @options[:expand_streets]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def handle_city
|
56
|
+
@city = []
|
57
|
+
if !address_hash[:city].nil?
|
58
|
+
@city.push(address_hash[:city])
|
59
|
+
@text = address_hash[:city].to_s
|
60
|
+
else
|
61
|
+
@city.push("")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def handle_state
|
66
|
+
if !address_hash[:region].nil?
|
67
|
+
@state = address_hash[:region]
|
68
|
+
# full_state = @state.strip # special case: New York
|
69
|
+
@state = State[@state] if @state.length > 2
|
70
|
+
elsif !address_hash[:state].nil?
|
71
|
+
@state = address_hash[:state]
|
72
|
+
elsif !address_hash[:country].nil?
|
73
|
+
@state = address_hash[:country]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle_zip
|
78
|
+
@zip = address_hash[:postal_code]
|
79
|
+
@plus4 = address_hash[:plus4]
|
80
|
+
if !@zip
|
81
|
+
@zip = @plus4 = ""
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|