Sha256: 195ecdf839fcad5f395d57db052a8c58328ae432273bab51d3a7688745aba396

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class RL
      # Serializes packages for R+L BOL API requests.
      class BOLPackagesSerializer
        # @param packages [Array<Physical::Package>] packages to serialize
        # @param options [BOLOptions] options for these packages
        # @return [Array<Hash>] serialized packages
        def self.call(packages:, options:)
          packages.flat_map do |package|
            package_options = options.options_for_package(package)
            package.items.map do |item|
              item_options = package_options.options_for_item(item)
              {
                IsHazmat: false,
                Pieces: 1,
                PackageType: "BOX",
                NMFCItemNumber: item_options.nmfc_primary_code,
                NMFCSubNumber: item_options.nmfc_sub_code,
                Class: item_options.freight_class,
                Weight: item.weight.convert_to(:pounds).value.ceil,
                Description: item.description.presence || "Commodities"
              }.compact
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
friendly_shipping-0.10.1 lib/friendly_shipping/services/rl/bol_packages_serializer.rb
friendly_shipping-0.10.0 lib/friendly_shipping/services/rl/bol_packages_serializer.rb
friendly_shipping-0.9.0 lib/friendly_shipping/services/rl/bol_packages_serializer.rb