class StreetSweeper::Address

Attributes

city[RW]
number[RW]
postal_code[RW]
postal_code_ext[RW]
prefix[RW]
prefix2[RW]
redundant_street_type[RW]
state[RW]
street[RW]
street2[RW]
street_type[RW]
street_type2[RW]
suffix[RW]
suffix2[RW]
unit[RW]
unit_prefix[RW]

Public Class Methods

new(args) click to toggle source
# File lib/street_sweeper/address.rb, line 22
def initialize(args)
  args.each do |attr, val|
    public_send("#{attr}=", val)
  end
end

Public Instance Methods

full_postal_code() click to toggle source
# File lib/street_sweeper/address.rb, line 28
def full_postal_code
  return nil unless postal_code
  postal_code_ext ? "#{postal_code}-#{postal_code_ext}" : postal_code
end
full_street_address() click to toggle source
# File lib/street_sweeper/address.rb, line 91
def full_street_address
  [line1, line2].reject(&:empty?).join(', ')
end
intersection?() click to toggle source
# File lib/street_sweeper/address.rb, line 41
def intersection?
  !street2.nil?
end
line1() click to toggle source
# File lib/street_sweeper/address.rb, line 45
def line1
  parts = []
  if intersection?
    parts << prefix if prefix
    parts << street
    parts << street_type if street_type
    parts << suffix if suffix
    parts << 'and'
    parts << prefix2 if prefix2
    parts << street2
    parts << street_type2 if street_type2
    parts << suffix2 if suffix2
  else
    parts << street_address_1
    parts << street_address_2
  end
  parts.join(' ').strip
end
line2() click to toggle source
# File lib/street_sweeper/address.rb, line 64
def line2
  parts = []
  parts << city  if city
  parts << state if state
  s = parts.join(', ')
  s += " #{full_postal_code}" if full_postal_code
  s.strip
end
state_fips() click to toggle source
# File lib/street_sweeper/address.rb, line 33
def state_fips
  Constants::FIPS_STATES[state]
end
state_name() click to toggle source
# File lib/street_sweeper/address.rb, line 37
def state_name
  (name = Constants::STATE_NAMES[state]) && name.capitalize
end
street_address_1() click to toggle source
# File lib/street_sweeper/address.rb, line 73
def street_address_1
  return line1 if intersection?
  parts = []
  parts << number
  parts << prefix if prefix
  parts << street if street
  parts << street_type if street_type && !redundant_street_type
  parts << suffix if suffix
  parts.join(' ').strip
end
street_address_2() click to toggle source
# File lib/street_sweeper/address.rb, line 84
def street_address_2
  parts = []
  parts << unit_prefix if unit_prefix
  parts << (unit_prefix ? unit : "\# #{unit}") if unit
  parts.join(' ').strip
end
to_h() click to toggle source
# File lib/street_sweeper/address.rb, line 95
def to_h
  instance_variables.each_with_object({}) do |var_name, hash|
    var_value = instance_variable_get(var_name)
    hash_name = var_name[1..-1].to_sym
    hash[hash_name] = var_value
  end
end