Skip to content

Commit

Permalink
Change unit/unitnum to sec_unit_type/sec_unit_num
Browse files Browse the repository at this point in the history
  • Loading branch information
timbunce committed May 3, 2011
1 parent f571808 commit e61c8a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -5,7 +5,7 @@ Revision history for Perl extension Geo::StreetAddress::US.
Fixed lower cased city direction thanks to Al Sary. RT#50476.
Fixed space in state name thanks to Nate Blaylock. RT#30109.
Allow ZIP+4 without hyphen thanks to Mark Pickett. RT#17445.
Added 'unit' (type) and 'unitnum' fields thanks to Evan S Kaufman. RT#44735.
Added sec_unit_type and sec_unit_num fields thanks to Evan S Kaufman. RT#44735.
Added support for more Secondary Unit Designators to unit field.
Added note to docs that future versions may add extra fields.
Increased minimum perl version to 5.8.1.
Expand Down
35 changes: 24 additions & 11 deletions US.pm
Expand Up @@ -84,15 +84,15 @@ for a list of abbreviations used.
Five digit ZIP postal code for the address, including leading zero, if needed.
=item unit
=item sec_unit_type
If the address includes a Secondary Unit Designator, such as a room, suite or
appartment, the C<unit> field will indicate the type of unit.
appartment, the C<sec_unit_type> field will indicate the type of unit.
=item unitnum
=item sec_unit_num
If the address includes a Secondary Unit Designator, such as a room, suite or appartment,
the C<unitnum> field will indicate the number of the unit (which may not be numeric).
the C<sec_unit_num> field will indicate the number of the unit (which may not be numeric).
=back
Expand Down Expand Up @@ -741,7 +741,7 @@ our %Addr_Match = (
# http://www.usps.com/ncsc/lookups/abbreviations.html#secunitdesig
# TODO add support for those that don't require a number
# TODO map to standard names/abbreviations
$Addr_Match{sec_unit_type} = qr/
$Addr_Match{sec_unit_type_numbered} = qr/
(su?i?te
|p\W*[om]\W*b(?:ox)?
|(?:ap|dep)(?:ar)?t(?:me?nt)?
Expand All @@ -756,14 +756,27 @@ our %Addr_Match = (
|spa?ce?
|stop
|tra?i?le?r
|box) (?{ $_{unit} = $^N })
|box) (?{ $_{sec_unit_type} = $^N })
/ix;

$Addr_Match{unit} = qr/
(?: (?:$Addr_Match{sec_unit_type} \W+)
| \#\W* (?{ $_{unit} = 'unit' })
$Addr_Match{sec_unit_type_unnumbered} = qr/
(ba?se?me?n?t
|fro?nt
|lo?bby
|lowe?r
|off?i?ce?
|pe?n?t?ho?u?s?e?
|rear
|side
|uppe?r
) (?{ $_{sec_unit_type} = $^N })
/ix;

$Addr_Match{sec_unit} = qr/
(?: (?:$Addr_Match{sec_unit_type_numbered} \W+)
| \#\W* (?{ $_{sec_unit_type} = 'unit' })
)
( [\w-]+) (?{ $_{unitnum}= $^N })
( [\w-]+) (?{ $_{sec_unit_num}= $^N })
/ix;

$Addr_Match{place} = qr/
Expand All @@ -778,7 +791,7 @@ our %Addr_Match = (
( $Addr_Match{number})\W* (?{ $_{number} = $^N })
(?:$Addr_Match{fraction}\W*)?
$Addr_Match{street}\W+
(?:$Addr_Match{unit}\W+)?
(?:$Addr_Match{sec_unit}\W+)?
$Addr_Match{place}
\W*$/ix;

Expand Down
8 changes: 4 additions & 4 deletions t/01_parser.t
Expand Up @@ -66,8 +66,8 @@ my %address = (
'suffix' => undef,
'type' => 'Hwy',
'prefix' => 'N',
'unit' => 'Suite',
'unitnum' => '500',
'sec_unit_type' => 'Suite',
'sec_unit_num' => '500',
},
"1005 N Gravenstein Hwy Suite 500 Sebastopol, CA" => {
'number' => '1005',
Expand All @@ -78,8 +78,8 @@ my %address = (
'suffix' => undef,
'type' => 'Hwy',
'prefix' => 'N',
'unit' => 'Suite',
'unitnum' => '500',
'sec_unit_type' => 'Suite',
'sec_unit_num' => '500',
},
"1005 N Gravenstein Highway, Sebastopol, CA, 95472" => {
'number' => '1005',
Expand Down

0 comments on commit e61c8a7

Please sign in to comment.