Class: StreetAddress::US
- Inherits:
-
Object
- Object
- StreetAddress::US
- Defined in:
- lib/street_address.rb
Defined Under Namespace
Classes: Address
Constant Summary collapse
- VERSION =
'1.0.5'
- DIRECTIONAL =
{ "north" => "N", "northeast" => "NE", "east" => "E", "southeast" => "SE", "south" => "S", "southwest" => "SW", "west" => "W", "northwest" => "NW" }
- DIRECTION_CODES =
DIRECTIONAL.invert
- STREET_TYPES =
{ "allee" => "aly", "alley" => "aly", "ally" => "aly", "anex" => "anx", "annex" => "anx", "annx" => "anx", "arcade" => "arc", "av" => "ave", "aven" => "ave", "avenu" => "ave", "avenue" => "ave", "avn" => "ave", "avnue" => "ave", "bayoo" => "byu", "bayou" => "byu", "beach" => "bch", "bend" => "bnd", "bluf" => "blf", "bluff" => "blf", "bluffs" => "blfs", "bot" => "btm", "bottm" => "btm", "bottom" => "btm", "boul" => "blvd", "boulevard" => "blvd", "boulv" => "blvd", "branch" => "br", "brdge" => "brg", "bridge" => "brg", "brnch" => "br", "brook" => "brk", "brooks" => "brks", "burg" => "bg", "burgs" => "bgs", "bypa" => "byp", "bypas" => "byp", "bypass" => "byp", "byps" => "byp", "camp" => "cp", "canyn" => "cyn", "canyon" => "cyn", "cape" => "cpe", "causeway" => "cswy", "causway" => "cswy", "cen" => "ctr", "cent" => "ctr", "center" => "ctr", "centers" => "ctrs", "centr" => "ctr", "centre" => "ctr", "circ" => "cir", "circl" => "cir", "circle" => "cir", "circles" => "cirs", "ck" => "crk", "cliff" => "clf", "cliffs" => "clfs", "club" => "clb", "cmp" => "cp", "cnter" => "ctr", "cntr" => "ctr", "cnyn" => "cyn", "common" => "cmn", "corner" => "cor", "corners" => "cors", "course" => "crse", "court" => "ct", "courts" => "cts", "cove" => "cv", "coves" => "cvs", "cr" => "crk", "crcl" => "cir", "crcle" => "cir", "crecent" => "cres", "creek" => "crk", "crescent" => "cres", "cresent" => "cres", "crest" => "crst", "crossing" => "xing", "crossroad" => "xrd", "crscnt" => "cres", "crsent" => "cres", "crsnt" => "cres", "crssing" => "xing", "crssng" => "xing", "crt" => "ct", "curve" => "curv", "dale" => "dl", "dam" => "dm", "div" => "dv", "divide" => "dv", "driv" => "dr", "drive" => "dr", "drives" => "drs", "drv" => "dr", "dvd" => "dv", "estate" => "est", "estates" => "ests", "exp" => "expy", "expr" => "expy", "express" => "expy", "expressway" => "expy", "expw" => "expy", "extension" => "ext", "extensions" => "exts", "extn" => "ext", "extnsn" => "ext", "falls" => "fls", "ferry" => "fry", "field" => "fld", "fields" => "flds", "flat" => "flt", "flats" => "flts", "ford" => "frd", "fords" => "frds", "forest" => "frst", "forests" => "frst", "forg" => "frg", "forge" => "frg", "forges" => "frgs", "fork" => "frk", "forks" => "frks", "fort" => "ft", "freeway" => "fwy", "freewy" => "fwy", "frry" => "fry", "frt" => "ft", "frway" => "fwy", "frwy" => "fwy", "garden" => "gdn", "gardens" => "gdns", "gardn" => "gdn", "gateway" => "gtwy", "gatewy" => "gtwy", "gatway" => "gtwy", "glen" => "gln", "glens" => "glns", "grden" => "gdn", "grdn" => "gdn", "grdns" => "gdns", "green" => "grn", "greens" => "grns", "grov" => "grv", "grove" => "grv", "groves" => "grvs", "gtway" => "gtwy", "harb" => "hbr", "harbor" => "hbr", "harbors" => "hbrs", "harbr" => "hbr", "haven" => "hvn", "havn" => "hvn", "height" => "hts", "heights" => "hts", "hgts" => "hts", "highway" => "hwy", "highwy" => "hwy", "hill" => "hl", "hills" => "hls", "hiway" => "hwy", "hiwy" => "hwy", "hllw" => "holw", "hollow" => "holw", "hollows" => "holw", "holws" => "holw", "hrbor" => "hbr", "ht" => "hts", "hway" => "hwy", "inlet" => "inlt", "island" => "is", "islands" => "iss", "isles" => "isle", "islnd" => "is", "islnds" => "iss", "jction" => "jct", "jctn" => "jct", "jctns" => "jcts", "junction" => "jct", "junctions" => "jcts", "junctn" => "jct", "juncton" => "jct", "key" => "ky", "keys" => "kys", "knol" => "knl", "knoll" => "knl", "knolls" => "knls", "la" => "ln", "lake" => "lk", "lakes" => "lks", "landing" => "lndg", "lane" => "ln", "lanes" => "ln", "ldge" => "ldg", "light" => "lgt", "lights" => "lgts", "lndng" => "lndg", "loaf" => "lf", "lock" => "lck", "locks" => "lcks", "lodg" => "ldg", "lodge" => "ldg", "loops" => "loop", "manor" => "mnr", "manors" => "mnrs", "meadow" => "mdw", "meadows" => "mdws", "medows" => "mdws", "mill" => "ml", "mills" => "mls", "mission" => "msn", "missn" => "msn", "mnt" => "mt", "mntain" => "mtn", "mntn" => "mtn", "mntns" => "mtns", "motorway" => "mtwy", "mount" => "mt", "mountain" => "mtn", "mountains" => "mtns", "mountin" => "mtn", "mssn" => "msn", "mtin" => "mtn", "neck" => "nck", "orchard" => "orch", "orchrd" => "orch", "overpass" => "opas", "ovl" => "oval", "parks" => "park", "parkway" => "pkwy", "parkways" => "pkwy", "parkwy" => "pkwy", "passage" => "psge", "paths" => "path", "pikes" => "pike", "pine" => "pne", "pines" => "pnes", "pk" => "park", "pkway" => "pkwy", "pkwys" => "pkwy", "pky" => "pkwy", "place" => "pl", "plain" => "pln", "plaines" => "plns", "plains" => "plns", "plaza" => "plz", "plza" => "plz", "point" => "pt", "points" => "pts", "port" => "prt", "ports" => "prts", "prairie" => "pr", "prarie" => "pr", "prk" => "park", "prr" => "pr", "rad" => "radl", "radial" => "radl", "radiel" => "radl", "ranch" => "rnch", "ranches" => "rnch", "rapid" => "rpd", "rapids" => "rpds", "rdge" => "rdg", "rest" => "rst", "ridge" => "rdg", "ridges" => "rdgs", "river" => "riv", "rivr" => "riv", "rnchs" => "rnch", "road" => "rd", "roads" => "rds", "route" => "rte", "rvr" => "riv", "shoal" => "shl", "shoals" => "shls", "shoar" => "shr", "shoars" => "shrs", "shore" => "shr", "shores" => "shrs", "skyway" => "skwy", "spng" => "spg", "spngs" => "spgs", "spring" => "spg", "springs" => "spgs", "sprng" => "spg", "sprngs" => "spgs", "spurs" => "spur", "sqr" => "sq", "sqre" => "sq", "sqrs" => "sqs", "squ" => "sq", "square" => "sq", "squares" => "sqs", "station" => "sta", "statn" => "sta", "stn" => "sta", "str" => "st", "strav" => "stra", "strave" => "stra", "straven" => "stra", "stravenue" => "stra", "stravn" => "stra", "stream" => "strm", "street" => "st", "streets" => "sts", "streme" => "strm", "strt" => "st", "strvn" => "stra", "strvnue" => "stra", "sumit" => "smt", "sumitt" => "smt", "summit" => "smt", "terr" => "ter", "terrace" => "ter", "throughway" => "trwy", "tpk" => "tpke", "tr" => "trl", "trace" => "trce", "traces" => "trce", "track" => "trak", "tracks" => "trak", "trafficway" => "trfy", "trail" => "trl", "trails" => "trl", "trk" => "trak", "trks" => "trak", "trls" => "trl", "trnpk" => "tpke", "trpk" => "tpke", "tunel" => "tunl", "tunls" => "tunl", "tunnel" => "tunl", "tunnels" => "tunl", "tunnl" => "tunl", "turnpike" => "tpke", "turnpk" => "tpke", "underpass" => "upas", "union" => "un", "unions" => "uns", "valley" => "vly", "valleys" => "vlys", "vally" => "vly", "vdct" => "via", "viadct" => "via", "viaduct" => "via", "view" => "vw", "views" => "vws", "vill" => "vlg", "villag" => "vlg", "village" => "vlg", "villages" => "vlgs", "ville" => "vl", "villg" => "vlg", "villiage" => "vlg", "vist" => "vis", "vista" => "vis", "vlly" => "vly", "vst" => "vis", "vsta" => "vis", "walks" => "walk", "well" => "wl", "wells" => "wls", "wy" => "way" }
- STREET_TYPES_LIST =
{}
- STATE_CODES =
{ "alabama" => "AL", "alaska" => "AK", "american samoa" => "AS", "arizona" => "AZ", "arkansas" => "AR", "california" => "CA", "colorado" => "CO", "connecticut" => "CT", "delaware" => "DE", "district of columbia" => "DC", "federated states of micronesia" => "FM", "florida" => "FL", "georgia" => "GA", "guam" => "GU", "hawaii" => "HI", "idaho" => "ID", "illinois" => "IL", "indiana" => "IN", "iowa" => "IA", "kansas" => "KS", "kentucky" => "KY", "louisiana" => "LA", "maine" => "ME", "marshall islands" => "MH", "maryland" => "MD", "massachusetts" => "MA", "michigan" => "MI", "minnesota" => "MN", "mississippi" => "MS", "missouri" => "MO", "montana" => "MT", "nebraska" => "NE", "nevada" => "NV", "new hampshire" => "NH", "new jersey" => "NJ", "new mexico" => "NM", "new york" => "NY", "north carolina" => "NC", "north dakota" => "ND", "northern mariana islands" => "MP", "ohio" => "OH", "oklahoma" => "OK", "oregon" => "OR", "palau" => "PW", "pennsylvania" => "PA", "puerto rico" => "PR", "rhode island" => "RI", "south carolina" => "SC", "south dakota" => "SD", "tennessee" => "TN", "texas" => "TX", "utah" => "UT", "vermont" => "VT", "virgin islands" => "VI", "virginia" => "VA", "washington" => "WA", "west virginia" => "WV", "wisconsin" => "WI", "wyoming" => "WY" }
- STATE_NAMES =
STATE_CODES.invert
- STATE_FIPS =
{ "01" => "AL", "02" => "AK", "04" => "AZ", "05" => "AR", "06" => "CA", "08" => "CO", "09" => "CT", "10" => "DE", "11" => "DC", "12" => "FL", "13" => "GA", "15" => "HI", "16" => "ID", "17" => "IL", "18" => "IN", "19" => "IA", "20" => "KS", "21" => "KY", "22" => "LA", "23" => "ME", "24" => "MD", "25" => "MA", "26" => "MI", "27" => "MN", "28" => "MS", "29" => "MO", "30" => "MT", "31" => "NE", "32" => "NV", "33" => "NH", "34" => "NJ", "35" => "NM", "36" => "NY", "37" => "NC", "38" => "ND", "39" => "OH", "40" => "OK", "41" => "OR", "42" => "PA", "44" => "RI", "45" => "SC", "46" => "SD", "47" => "TN", "48" => "TX", "49" => "UT", "50" => "VT", "51" => "VA", "53" => "WA", "54" => "WV", "55" => "WI", "56" => "WY", "72" => "PR", "78" => "VI" }
- FIPS_STATES =
STATE_FIPS.invert
Class Attribute Summary collapse
-
.address_regexp ⇒ Object
Returns the value of attribute address_regexp.
-
.city_and_state_regexp ⇒ Object
Returns the value of attribute city_and_state_regexp.
-
.corner_regexp ⇒ Object
Returns the value of attribute corner_regexp.
-
.direct_regexp ⇒ Object
Returns the value of attribute direct_regexp.
-
.fraction_regexp ⇒ Object
Returns the value of attribute fraction_regexp.
-
.informal_address_regexp ⇒ Object
Returns the value of attribute informal_address_regexp.
-
.number_regexp ⇒ Object
Returns the value of attribute number_regexp.
-
.place_regexp ⇒ Object
Returns the value of attribute place_regexp.
-
.state_regexp ⇒ Object
Returns the value of attribute state_regexp.
-
.street_regexp ⇒ Object
Returns the value of attribute street_regexp.
-
.street_type_regexp ⇒ Object
Returns the value of attribute street_type_regexp.
-
.unit_regexp ⇒ Object
Returns the value of attribute unit_regexp.
-
.zip_regexp ⇒ Object
Returns the value of attribute zip_regexp.
Class Method Summary collapse
- .parse(location, args = {}) ⇒ Object
-
.parse_address(addr) ⇒ Object
parses only an address and returnsan instance of StreetAddress::US::Address or nil if the address cannot be parsed.
- .parse_informal_address(addr) ⇒ Object
-
.parse_intersection(inter) ⇒ Object
parses only an intersection and returnsan instance of StreetAddress::US::Address or nil if the intersection cannot be parsed ====example address = StreetAddress::US.parse(‘Hollywood & Vine, Los Angeles, CA’) assert address.intersection?.
Class Attribute Details
.address_regexp ⇒ Object
Returns the value of attribute address_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def address_regexp @address_regexp end |
.city_and_state_regexp ⇒ Object
Returns the value of attribute city_and_state_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def city_and_state_regexp @city_and_state_regexp end |
.corner_regexp ⇒ Object
Returns the value of attribute corner_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def corner_regexp @corner_regexp end |
.direct_regexp ⇒ Object
Returns the value of attribute direct_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def direct_regexp @direct_regexp end |
.fraction_regexp ⇒ Object
Returns the value of attribute fraction_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def fraction_regexp @fraction_regexp end |
.informal_address_regexp ⇒ Object
Returns the value of attribute informal_address_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def informal_address_regexp @informal_address_regexp end |
.number_regexp ⇒ Object
Returns the value of attribute number_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def number_regexp @number_regexp end |
.place_regexp ⇒ Object
Returns the value of attribute place_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def place_regexp @place_regexp end |
.state_regexp ⇒ Object
Returns the value of attribute state_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def state_regexp @state_regexp end |
.street_regexp ⇒ Object
Returns the value of attribute street_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def street_regexp @street_regexp end |
.street_type_regexp ⇒ Object
Returns the value of attribute street_type_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def street_type_regexp @street_type_regexp end |
.unit_regexp ⇒ Object
Returns the value of attribute unit_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def unit_regexp @unit_regexp end |
.zip_regexp ⇒ Object
Returns the value of attribute zip_regexp.
574 575 576 |
# File 'lib/street_address.rb', line 574 def zip_regexp @zip_regexp end |
Class Method Details
.parse(location, args = {}) ⇒ Object
668 669 670 671 672 673 674 675 676 |
# File 'lib/street_address.rb', line 668 def parse(location, args = {}) if Regexp.new(corner_regexp, Regexp::IGNORECASE).match(location) parse_intersection(location) elsif args[:informal] parse_address(location) || parse_informal_address(location) else parse_address(location); end end |
.parse_address(addr) ⇒ Object
parses only an address and returnsan instance of
StreetAddress::US::Address or nil if the address cannot be parsed
example
address = StreetAddress::US.parse('1600 Pennsylvania Ave Washington, DC 20006')
assert !address.intersection?
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/street_address.rb', line 724 def parse_address(addr) regex = Regexp.new(address_regexp, Regexp::IGNORECASE + Regexp::EXTENDED) return unless match = regex.match(addr) normalize_address( StreetAddress::US::Address.new( :number => match[1], :street => match[5] || match[10] || match[2], :street_type => match[6] || match[3], :unit => match[14], :unit_prefix => match[13], :suffix => match[7] || match[12], :prefix => match[4], :city => match[15], :state => match[16], :postal_code => match[17], :postal_code_ext => match[18] ) ) end |
.parse_informal_address(addr) ⇒ Object
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/street_address.rb', line 746 def parse_informal_address(addr) regex = Regexp.new(informal_address_regexp, Regexp::IGNORECASE + Regexp::EXTENDED) return unless match = regex.match(addr) normalize_address( StreetAddress::US::Address.new( :number => match[1], :street => match[5] || match[10] || match[2], :street_type => match[6] || match[3], :unit => match[14], :unit_prefix => match[13], :suffix => match[7] || match[12], :prefix => match[4], :city => match[15], :state => match[16], :postal_code => match[17], :postal_code_ext => match[18] ) ) end |
.parse_intersection(inter) ⇒ Object
parses only an intersection and returnsan instance of
StreetAddress::US::Address or nil if the intersection cannot be parsed
example
address = StreetAddress::US.parse('Hollywood & Vine, Los Angeles, CA')
assert address.intersection?
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/street_address.rb', line 687 def parse_intersection(inter) regex = Regexp.new( '\A\W*' + street_regexp + '\W*? \s+' + corner_regexp + '\s+' + street_regexp + '\W+' + place_regexp + '\W*\Z', Regexp::IGNORECASE + Regexp::EXTENDED ) return unless match = regex.match(inter) normalize_address( StreetAddress::US::Address.new( :street => match[4] || match[9], :street_type => match[5], :suffix => match[6], :prefix => match[3], :street2 => match[15] || match[20], :street_type2 => match[16], :suffix2 => match[17], :prefix2 => match[14], :city => match[23], :state => match[24], :postal_code => match[25] ) ) end |