Class: MelissaData::NativeObject::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/melissadata/native_object/address.rb

Instance Attribute Summary

Attributes inherited from Base

#data_dir, #input, #obj, #output, #result_codes, #results_string

Instance Method Summary collapse

Methods inherited from Base

#license, #process, #process_result_codes, #valid_input?

Constructor Details

#initialize(opts = {}) ⇒ Address

Returns a new instance of Address.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/melissadata/native_object/address.rb', line 5

def initialize(opts={})
  @obj = MdAddrRubyWrapper::MdAddr.new
  obj.SetPathToUSFiles(data_dir)
  obj.SetUseUSPSPreferredCityNames(1)

  @result_codes = [
    ['AS01', "Address matched to postal database"],
    ['AS09', "Foreign postal code detected"],
    ['AS10', "Address matched to CMRA"],
    ['AS12', "Address deliverable by non-USPS carriers"],
    ['AS13', "Address has been updated by LACS"],
    ['AS14', "Suite appended by SuiteLink"],
    ['AS15', "Suite appended by AddressPlus"],
    ['AS16', "Address is vacant"],
    ['AS17', "Alternate delivery"],
    ['AE01', "Zip code"],
    ['AE02', "Unknown street"],
    ['AE03', "Component mismatch"],
    ['AE04', "Non-deliverable address"],
    ['AE05', "Multiple match"],
    ['AE06', "Early warning system error"],
    ['AE07', "Missing minimum address input"],
    ['AE08', "Suite range invalid"],
    ['AE09', "Suite range missing"],
    ['AE10', "Primary range invalid"],
    ['AE11', "Primary range missing"],
    ['AE12', "PO, HC, or RR box number invalid"],
    ['AE13', "PO, HC, or RR box number missing"],
    ['AE14', "CMRA secondary missing"],
    ['AE15', "Demo mode"],
    ['AE16', "Expired database"]
  ]

  @defaults = {
    :company => '',
    :address => '',
    :address2 => '',
    :city => '',
    :state => '',
    :zip => '',
    :last_name => ''
  }

  # At least one of these needs to be present
  @required_fields = [:address, :city, :state, :zip]

  super
end

Instance Method Details

#assign_valuesObject



67
68
69
70
71
72
73
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/melissadata/native_object/address.rb', line 67

def assign_values
  @output = {
    :company => obj.GetCompany,
    :address => obj.GetAddress,
    :address2 => obj.GetAddress2,
    :suite => obj.GetSuite,
    :city => obj.GetCity,
    :state => obj.GetState,
    :zip => obj.GetZip,
    :plus4 => obj.GetPlus4,
    :country_code => obj.GetCountryCode,
    :urbanization => obj.GetUrbanization,

    :parsed_address_range => obj.GetParsedAddressRange,
    :parsed_pre_direction => obj.GetParsedPreDirection,
    :parsed_street_name => obj.GetParsedStreetName,
    :parsed_post_direction => obj.GetParsedPostDirection,
    :parsed_suffix => obj.GetParsedSuffix,
    :parsed_suite_name => obj.GetParsedSuiteName,
    :parsed_suite_range => obj.GetParsedSuiteRange,
    :parsed_garbage => obj.GetParsedGarbage,
    :parsed_private_mailbox_name => obj.GetParsedPrivateMailboxName,
    :parsed_private_mailbox_number => obj.GetParsedPrivateMailboxNumber,

    :carrier_route => obj.GetCarrierRoute,
    :delivery_point_code => obj.GetDeliveryPointCode,
    :delivery_point_check_digit => obj.GetDeliveryPointCheckDigit,

    :address_type_code => obj.GetAddressTypeCode,
    :address_type_string => obj.GetAddressTypeString,

    :city_abbrev => obj.GetCityAbbreviation,

    :cmra => obj.GetCMRA, # Commercial Mail Receiving Agency
    :private_mailbox => obj.GetPrivateMailbox, # mailbox number at the CMRA

    :msa => obj.GetMsa,
    :pmsa => obj.GetPmsa,

    :time_zone => obj.GetTimeZone,
    :time_zone_code => obj.GetTimeZoneCode,

    :county_name => obj.GetCountyName,
    :county_fips => obj.GetCountyFips,
    :congressional_district => obj.GetCongressionalDistrict,
    :zip_type_code => obj.GetZipType
  }

  output[:zip_type] = case output[:zip_type_code]
                        when 'P' then 'PO Boxes only'
                        when 'U' then 'Unique - organization or government'
                        when 'M' then 'Military'
                        else       'Standard'
                      end

  output[:zip9] = "#{output[:zip]}-#{output[:plus4]}" if output[:plus4].present?
  output[:zip11] = "#{output[:zip9]}-#{output[:delivery_point_code]}" if output[:delivery_point_code].present?
end

#parse_inputObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/melissadata/native_object/address.rb', line 54

def parse_input
  obj.ClearProperties
  obj.SetCompany   input[:company].to_s
  obj.SetAddress   input[:address].to_s
  obj.SetAddress2  input[:address2].to_s
  obj.SetCity      input[:city].to_s
  obj.SetState     input[:state].to_s
  obj.SetZip       input[:zip].to_s
  obj.SetLastName  input[:last_name].to_s

  obj.VerifyAddress
end