Class: UPS::Builders::OrganisationBuilder

Inherits:
BuilderBase
  • Object
show all
Includes:
Ox
Defined in:
lib/ups/builders/organisation_builder.rb

Overview

The OrganisationBuilder class builds UPS XML Organization Objects.

Author:

  • Paul Trippett

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from BuilderBase

#access_request, #document, #license_number, #password, #root, #shipment_root, #user_id

Instance Method Summary collapse

Methods inherited from BuilderBase

#add_access_request, #add_package, #add_payment_information, #add_rate_information, #add_request, #add_ship_from, #add_ship_to, #add_shipper

Constructor Details

#initialize(name, opts = {}) ⇒ OrganisationBuilder

Initializes a new AddressBuilder object

Parameters:

  • opts (Hash) (defaults to: {})

    The Organization and Address Parts

Options Hash (opts):

  • :company_name (String)

    Company Name

  • :phone_number (String)

    Phone Number

  • :address_line_1 (String)

    Address Line 1

  • :city (String)

    City

  • :state (String)

    State

  • :postal_code (String)

    Zip or Postal Code

  • :country (String)

    Country

Since:

  • 0.1.0


28
29
30
31
# File 'lib/ups/builders/organisation_builder.rb', line 28

def initialize(name, opts = {})
  self.name = name
  self.opts = opts
end

Instance Attribute Details

#nameString

The Containing XML Element Name

Returns:

  • (String)

    the current value of name

Since:

  • 0.1.0


13
14
15
# File 'lib/ups/builders/organisation_builder.rb', line 13

def name
  @name
end

#optsHash

The Organization and Address Parts

Returns:

  • (Hash)

    the current value of opts

Since:

  • 0.1.0


13
14
15
# File 'lib/ups/builders/organisation_builder.rb', line 13

def opts
  @opts
end

Instance Method Details

#addressOx::Element

Returns an XML representation of address

Returns:

  • (Ox::Element)

    An instance of AddressBuilder containing the address

Since:

  • 0.1.0


59
60
61
# File 'lib/ups/builders/organisation_builder.rb', line 59

def address
  AddressBuilder.new(opts).to_xml
end

#attention_nameOx::Element

Returns an XML representation of AttentionName for which we use company name

Returns:

  • (Ox::Element)

    XML representation of company_name part

Since:

  • 0.1.0


51
52
53
# File 'lib/ups/builders/organisation_builder.rb', line 51

def attention_name
  element_with_value('AttentionName', opts[:attention_name][0..34])
end

#company_nameOx::Element

Returns an XML representation of company_name

Returns:

  • (Ox::Element)

    XML representation of company_name

Since:

  • 0.1.0


36
37
38
# File 'lib/ups/builders/organisation_builder.rb', line 36

def company_name
  element_with_value('CompanyName', opts[:company_name][0..34])
end

#phone_numberOx::Element

Returns an XML representation of phone_number

Returns:

  • (Ox::Element)

    XML representation of phone_number

Since:

  • 0.1.0


43
44
45
# File 'lib/ups/builders/organisation_builder.rb', line 43

def phone_number
  element_with_value('PhoneNumber', opts[:phone_number][0..14])
end

#to_xmlOx::Element

Returns an XML representation of a UPS Organization

Returns:

  • (Ox::Element)

    XML representation of the current object

Since:

  • 0.1.0


66
67
68
69
70
71
72
73
# File 'lib/ups/builders/organisation_builder.rb', line 66

def to_xml
  Element.new(name).tap do |org|
    org << company_name
    org << phone_number
    org << attention_name
    org << address
  end
end