Sha256: b2cba14c0331643964abcfb470b82c962f48ab008d8d4c176eb6438af975af9f

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class Ups
      class SerializePackageNode
        def self.call(xml:, package:)
          xml.Package do
            xml.PackagingType do
              xml.Code('02')
            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

            if package.properties[:shipper_release]
              xml.PackageServiceOptions do
                xml.ShipperReleaseIndicator
              end
            end

            Array.wrap(package.properties[:reference_numbers]).each do |reference_number_info|
              xml.ReferenceNumber do
                xml.Code(reference_number_info[:code] || "")
                xml.Value(reference_number_info[:value])
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
friendly_shipping-0.3.4 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.3.3 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.3.0 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.2.6 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.2.5 lib/friendly_shipping/services/ups/serialize_package_node.rb
friendly_shipping-0.2.4 lib/friendly_shipping/services/ups/serialize_package_node.rb