Sha256: 057e7595cccb1bf1ec42dd6d5c3901e222770b8e8831eb405b256eb707e4d6e8

Contents?: true

Size: 1.86 KB

Versions: 15

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class Ups
      class SerializePackageNode
        def self.call(
          xml:,
          package:,
          reference_numbers: {},
          delivery_confirmation_code: nil,
          shipper_release: false
        )
          xml.Package do
            xml.PackagingType do
              xml.Code('02')
            end

            if package.items.any?(&:description)
              xml.Description(package.items.map(&:description).compact.join(', '))
            end

            if package.dimensions.all? { |dim| !dim.value.zero? && !dim.value.infinite? }
              xml.Dimensions do
                xml.UnitOfMeasurement do
                  xml.Code('IN')
                end
                xml.Length(package.length.convert_to(:inches).value.to_f.round(3))
                xml.Width(package.width.convert_to(:inches).value.to_f.round(3))
                xml.Height(package.height.convert_to(:inches).value.to_f.round(3))
              end
            end

            xml.PackageWeight do
              xml.UnitOfMeasurement do
                xml.Code('LBS')
              end

              xml.Weight([package.weight.convert_to(:pounds).value.to_f.round(2).ceil, 1].max)
            end

            xml.PackageServiceOptions do
              if shipper_release
                xml.ShipperReleaseIndicator
              end
              if delivery_confirmation_code
                xml.DeliveryConfirmation do
                  xml.DCISType(delivery_confirmation_code)
                end
              end
            end

            reference_numbers.each do |reference_code, reference_number|
              xml.ReferenceNumber do
                xml.Code(reference_code)
                xml.Value(reference_number)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
friendly_shipping-0.4.14 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.13 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.12 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.11 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.10 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.9 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.8 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.7 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.6 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.5 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.4 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.3 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.2 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.1 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.4.0 lib/friendly_shipping/services/ups/serialize_package_node.rb