Object
# File lib/street_address.rb, line 651 def parse(location) if Regexp.new(corner_regexp, Regexp::IGNORECASE).match(location) parse_intersection(location); else parse_address(location); end end
parses only an address and returnsan instance of StreetAddress::US::Address or nil if the address cannot be parsed
address = StreetAddress::US.parse('1600 Pennsylvania Ave Washington, DC 20006') assert !address.intersection?
# File lib/street_address.rb, line 706 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
parses only an intersection and returnsan instance of StreetAddress::US::Address or nil if the intersection cannot be parsed
address = StreetAddress::US.parse('Hollywood & Vine, Los Angeles, CA') assert address.intersection?
# File lib/street_address.rb, line 669 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
Generated with the Darkfish Rdoc Generator 2.