Class: FriendlyShipping::Services::RL::BOLPackagesSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/rl/bol_packages_serializer.rb

Overview

Serializes packages for R+L BOL API requests.

Class Method Summary collapse

Class Method Details

.call(packages:, options:) ⇒ Array<Hash>

Returns serialized packages.

Parameters:

  • packages (Array<Physical::Package>)

    packages to serialize

  • options (BOLOptions)

    options for these packages

Returns:

  • (Array<Hash>)

    serialized packages



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/friendly_shipping/services/rl/bol_packages_serializer.rb', line 11

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