From e61c8a75e707deb2b0b07cf74afa99e6e4f8ca7e Mon Sep 17 00:00:00 2001 From: Tim Bunce Date: Tue, 3 May 2011 09:38:20 -0700 Subject: [PATCH] Change unit/unitnum to sec_unit_type/sec_unit_num --- Changes | 2 +- US.pm | 35 ++++++++++++++++++++++++----------- t/01_parser.t | 8 ++++---- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Changes b/Changes index c99cf36..3e99f11 100644 --- a/Changes +++ b/Changes @@ -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. diff --git a/US.pm b/US.pm index e95dab1..167be43 100644 --- a/US.pm +++ b/US.pm @@ -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 field will indicate the type of unit. +appartment, the C 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 field will indicate the number of the unit (which may not be numeric). +the C field will indicate the number of the unit (which may not be numeric). =back @@ -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)? @@ -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/ @@ -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; diff --git a/t/01_parser.t b/t/01_parser.t index ade152e..bac46f3 100644 --- a/t/01_parser.t +++ b/t/01_parser.t @@ -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', @@ -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',