Class: Shipping::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/ups_shipping/address.rb

Constant Summary collapse

ADDRESS_TYPES =
%w{residential commercial po_box}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Address

Returns a new instance of Address.



8
9
10
11
12
13
14
15
# File 'lib/ups_shipping/address.rb', line 8

def initialize(options={})
  @address_lines = options[:address_lines]
  @city = options[:city]
  @state = options[:state]
  @zip = options[:zip]
  @country = options[:country]
  @type = options[:type]
end

Instance Attribute Details

#address_linesObject

Returns the value of attribute address_lines.



6
7
8
# File 'lib/ups_shipping/address.rb', line 6

def address_lines
  @address_lines
end

#cityObject

Returns the value of attribute city.



6
7
8
# File 'lib/ups_shipping/address.rb', line 6

def city
  @city
end

#countryObject

Returns the value of attribute country.



6
7
8
# File 'lib/ups_shipping/address.rb', line 6

def country
  @country
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/ups_shipping/address.rb', line 6

def state
  @state
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/ups_shipping/address.rb', line 6

def type
  @type
end

#zipObject

Returns the value of attribute zip.



6
7
8
# File 'lib/ups_shipping/address.rb', line 6

def zip
  @zip
end

Instance Method Details

#build(xml) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ups_shipping/address.rb', line 17

def build(xml)
  xml.Address {
    xml.AddressLine1 @address_lines[0]
    xml.City @city
    xml.StateProvinceCode @state
    xml.PostalCode @zip
    xml.CountryCode @country
  }
end

#to_xmlObject



27
28
29
30
31
32
# File 'lib/ups_shipping/address.rb', line 27

def to_xml()
  builder = Nokogiri::XML::Builder.new do |xml|
    build(xml)
  end
  builder.to_xml
end