Class: Melissa::AddrObj

Inherits:
Object
  • Object
show all
Defined in:
lib/melissa/addr_obj.rb

Direct Known Subclasses

AddrObjLive, AddrObjMock

Defined Under Namespace

Classes: AddressStruct

Constant Summary collapse

@@melissa_attributes =
%w(
  Company
  LastName
  Address
  Address2
  Suite
  City
  CityAbbreviation
  State
  Zip
  Plus4
  CarrierRoute
  DeliveryPointCode
  DeliveryPointCheckDigit
  CountyFips
  CountyName
  AddressTypeCode
  AddressTypeString
  Urbanization
  CongressionalDistrict
  LACS
  LACSLinkIndicator
  RBDI
  PrivateMailbox
  TimeZoneCode
  TimeZone
  Msa
  Pmsa
  DefaultFlagIndicator
  SuiteStatus
  EWSFlag
  CMRA
  DsfNoStats
  DsfVacant
  CountryCode
  ZipType
  FalseTable
  DPVFootnotes
  LACSLinkReturnCode
  SuiteLinkReturnCode
  ELotNumber
  ELotOrder
  AddressKey
)
@@good_codes =
['AS01', 'AS02', 'AS03']
@@bad_codes =
['AC02', 'AC03']
@@callbacks =
ThreadSafe::Array.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_callback(&callback) ⇒ Object

Allow callbacks to intercept response and perform whatever misc stuff (hint: victim_statements)



59
60
61
# File 'lib/melissa/addr_obj.rb', line 59

def self.add_callback(&callback)
  @@callbacks << callback
end

Instance Method Details

#address_structObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/melissa/addr_obj.rb', line 74

def address_struct
  @address_struct = begin
    if valid?
      if address_type_string == 'Street' || address_type_string == 'Highrise'
        match = self.address.match /^(\S+)\s?(N|NE|E|SE|S|SW|W|NW|) (\S.*?)\s?(N|NE|E|SE|S|SW|W|NW|)$/
      end
    elsif self.address
      match = self.address.match /^(\d\S*)\s?(N|NE|E|SE|S|SW|W|NW|) (\S.*?)\s?(N|NE|E|SE|S|SW|W|NW|)$/
    end
    if match
      # Parse out the optional suffix
      street_match = match[3].match /(\S.*?)( [A-Za-z]{2,4}|)$/
      if street_match
        name, suffix = street_match[1], street_match[2].strip
      else
        name, suffix = match[3], ''
      end
      AddressStruct.new(match[1], match[2], name, suffix, match[4])
    elsif self.address
      AddressStruct.new('', '', self.address, '', '')
    else
      AddressStruct.new
    end
  end
end

#delivery_pointObject



63
64
65
# File 'lib/melissa/addr_obj.rb', line 63

def delivery_point
  "#{zip}#{plus4}#{delivery_point_code}"
end

#time_zone_offsetObject



67
68
69
70
71
72
# File 'lib/melissa/addr_obj.rb', line 67

def time_zone_offset
  time_zone = TIME_ZONES[self.time_zone_code]
  return nil unless time_zone
  time_zone = 'US/Arizona' if self.state == 'AZ'
  return Time.now.in_time_zone(time_zone).utc_offset / -60
end