Class: USPS::Response::AddressStandardization

Inherits:
Base
  • Object
show all
Defined in:
lib/usps/response/address_standardization.rb

Instance Attribute Summary

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

parse

Constructor Details

#initialize(addresses, xml) ⇒ AddressStandardization

Returns a new instance of AddressStandardization.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/usps/response/address_standardization.rb', line 6

def initialize(addresses, xml)
  @addresses = {}

  [addresses].flatten.each_with_index do |addy, i|
    @addresses[addy] = parse(xml.search("Address[@ID='#{i}']"))

    # Name is not sent nor received so lets make sure to set it so the
    # standardized version is roughly equivalent
    @addresses[addy].name = addy.name
  end
end

Instance Method Details

#addressesObject



25
26
27
# File 'lib/usps/response/address_standardization.rb', line 25

def addresses
  @addresses
end

#get(address) ⇒ Object Also known as: []

Returns an address representing the standardized version of the given address from the results of the query.



20
21
22
# File 'lib/usps/response/address_standardization.rb', line 20

def get(address)
  @addresses[address]
end

#to_hObject



29
30
31
32
33
34
35
36
# File 'lib/usps/response/address_standardization.rb', line 29

def to_h
  hash = {}
  @addresses.each_pair do |key, value|
    hash[key.to_h] = value.to_h
  end
  
  hash
end