class Indirizzo::Address
The Address
class takes a US street address or place name and constructs a list of possible structured parses of the address string.
Attributes
city[RW]
country[RW]
number[RW]
options[RW]
plus4[RW]
prenum[RW]
state[RW]
street[RW]
sufnum[RW]
text[RW]
zip[RW]
Public Class Methods
new(text, options={})
click to toggle source
Takes an address or place name string as its sole argument.
# File lib/indirizzo/address.rb, line 24 def initialize (text, options={}) @options = {:expand_streets => true}.merge(options) raise ArgumentError, "no text provided" unless text and !text.empty? if text.class == Hash @text = "" assign_text_to_address text else @text = clean text parse end end
Public Instance Methods
assign_text_to_address(text)
click to toggle source
# File lib/indirizzo/address.rb, line 42 def assign_text_to_address(text) @text, @city, @street, @number, @prenum, @sufnum, @full_state, @state, @zip, @plus4, @country = AddressHashExtractor.extract(text, @options) end
city=(strings)
click to toggle source
# File lib/indirizzo/address.rb, line 70 def city= (strings) # NOTE: This will still fail on: 100 Broome St, 33333 (if 33333 is # Broome, MT or what) strings = expand_streets(strings) # fix for "Mountain View" -> "Mountain Vw" match = Regexp.new('\s*\b(?:' + strings.join("|") + ')\b\s*$', Regexp::IGNORECASE) @street = @street.map {|string| string.gsub(match, '')}.select {|s|!s.empty?} end
city_parts()
click to toggle source
# File lib/indirizzo/address.rb, line 66 def city_parts City.city_parts(@city) end
clean(value)
click to toggle source
Removes any characters that aren't strictly part of an address string.
# File lib/indirizzo/address.rb, line 38 def clean (value) Helper.clean(value) end
expand_numbers(string)
click to toggle source
# File lib/indirizzo/address.rb, line 46 def expand_numbers (string) NumberHelper.expand_numbers(string) end
expand_streets(street)
click to toggle source
# File lib/indirizzo/address.rb, line 54 def expand_streets(street) Street.expand(street) end
intersection?()
click to toggle source
# File lib/indirizzo/address.rb, line 82 def intersection? !Match[:at].match(@text).nil? end
parse()
click to toggle source
# File lib/indirizzo/address.rb, line 50 def parse @city, @street, @number, @prenum, @sufnum, @full_state, @state, @zip, @plus4, @country = Parser.new(@text, @options).parse end
po_box?()
click to toggle source
# File lib/indirizzo/address.rb, line 78 def po_box? !Match[:po_box].match(@text).nil? end
remove_noise_words(strings)
click to toggle source
# File lib/indirizzo/address.rb, line 62 def remove_noise_words(strings) Helper.remove_noise_words(strings) end
street_parts()
click to toggle source
# File lib/indirizzo/address.rb, line 58 def street_parts Street.parts(@street, @number) end