Method: ActiveShipping::UPS#location_from_address_key_format_node

Defined in:
lib/active_shipping/carriers/ups.rb

#location_from_address_key_format_node(address) ⇒ Object (protected)

Converts from a AddressKeyFormat XML node to a Location



1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
# File 'lib/active_shipping/carriers/ups.rb', line 1057

def location_from_address_key_format_node(address)
  return nil unless address
  country = address.at('CountryCode').try(:text)
  country = 'US' if country == 'ZZ' # Sometimes returned by SUREPOST in the US

  address_lines = address.css('AddressLine')

  Location.new(
    :country     => country,
    :postal_code => address.at('PostcodePrimaryLow').try(:text),
    :province    => address.at('PoliticalDivision1').try(:text),
    :city        => address.at('PoliticalDivision2').try(:text),
    :address1    => address_lines[0].try(:text),
    :address2    => address_lines[1].try(:text),
    :address3    => address_lines[2].try(:text),
  )
end