Class: UPS::Builders::InternationalInvoiceBuilder

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

Overview

The InternationalInvoiceBuilder class builds UPS XML International invoice Objects.

Author:

  • Calvin Hughes

Since:

  • 0.9.3

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_insurance_charge, #add_itemized_payment_information, #add_master_carton_id, #add_master_carton_indicator, #add_package, #add_payment_information, #add_rate_information, #add_request, #add_ship_from, #add_ship_to, #add_shipment_delivery_confirmation, #add_shipment_direct_delivery_only, #add_shipper, #add_sold_to

Constructor Details

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

Returns a new instance of InternationalInvoiceBuilder.

Since:

  • 0.9.3



16
17
18
19
# File 'lib/ups/builders/international_invoice_builder.rb', line 16

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.9.3



11
12
13
# File 'lib/ups/builders/international_invoice_builder.rb', line 11

def name
  @name
end

#optsHash

The international invoice parts

Returns:

  • (Hash)

    the current value of opts

Since:

  • 0.9.3



11
12
13
# File 'lib/ups/builders/international_invoice_builder.rb', line 11

def opts
  @opts
end

Instance Method Details

#currency_codeObject

Since:

  • 0.9.3



45
46
47
# File 'lib/ups/builders/international_invoice_builder.rb', line 45

def currency_code
  element_with_value('CurrencyCode', opts[:currency_code])
end

#declaration_statementObject

Since:

  • 0.9.3



37
38
39
# File 'lib/ups/builders/international_invoice_builder.rb', line 37

def declaration_statement
  element_with_value('DeclarationStatement', opts[:declaration_statement])
end

#discountObject

Since:

  • 0.9.3



53
54
55
# File 'lib/ups/builders/international_invoice_builder.rb', line 53

def discount
  multi_valued('Discount', MonetaryValue: opts[:discount])
end

#form_typeObject

Since:

  • 0.9.3



21
22
23
# File 'lib/ups/builders/international_invoice_builder.rb', line 21

def form_type
  element_with_value('FormType', '01')
end

#freight_chargeObject

Since:

  • 0.9.3



49
50
51
# File 'lib/ups/builders/international_invoice_builder.rb', line 49

def freight_charge
  multi_valued('FreightCharges', MonetaryValue: opts[:freight_charge])
end

#invoice_dateObject

Since:

  • 0.9.3



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

def invoice_date
  element_with_value('InvoiceDate', opts[:invoice_date])
end

#invoice_numberObject

Since:

  • 0.9.3



25
26
27
# File 'lib/ups/builders/international_invoice_builder.rb', line 25

def invoice_number
  element_with_value('InvoiceNumber', opts[:invoice_number])
end

#product_container(opts = {}) ⇒ Object

Since:

  • 0.9.3



63
64
65
# File 'lib/ups/builders/international_invoice_builder.rb', line 63

def product_container(opts = {})
  InternationalInvoiceProductBuilder.new('Product', opts).to_xml
end

#product_detailsObject

Since:

  • 0.9.3



57
58
59
60
61
# File 'lib/ups/builders/international_invoice_builder.rb', line 57

def product_details
  opts[:products].map do |product_opts|
    product_container(product_opts)
  end
end

#reason_for_exportObject

Since:

  • 0.9.3



41
42
43
# File 'lib/ups/builders/international_invoice_builder.rb', line 41

def reason_for_export
  element_with_value('ReasonForExport', opts[:reason_for_export])
end

#terms_of_shipmentObject

Since:

  • 0.9.3



33
34
35
# File 'lib/ups/builders/international_invoice_builder.rb', line 33

def terms_of_shipment
  element_with_value('TermsOfShipment', opts[:terms_of_shipment])
end

#to_xmlOx::Element

Returns an XML representation of the current object

Returns:

  • (Ox::Element)

    XML representation of the current object

Since:

  • 0.9.3



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ups/builders/international_invoice_builder.rb', line 70

def to_xml
  Element.new(name).tap do |international_form|
    international_form << form_type
    international_form << invoice_number if opts[:invoice_number]
    international_form << invoice_date
    international_form << terms_of_shipment if opts[:terms_of_shipment]
    international_form << declaration_statement if opts[:declaration_statement]
    international_form << reason_for_export
    international_form << currency_code
    international_form << freight_charge
    international_form << discount

    product_details.each do |product_detail|
      international_form << product_detail
    end
  end
end