Sha256: f7f55510be310ed4a4948c5b9afdfcc6619823b51c1328028ae63e619c9c312b

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class TForceFreight
      # Generates a reference hash for JSON serialization.
      class GenerateReferenceHash
        class << self
          # @param reference_numbers [Array] reference numbers for the Bill of Lading
          # @return [Hash] reference hash suitable for JSON request
          def call(reference_numbers:)
            return {} unless reference_numbers

            references = reference_numbers.map do |reference_number|
              {
                number: reference_number[:value],
                type: reference_number[:code],
                quantity: reference_number[:quantity],
                weight: reference_number[:weight]
              }.compact
            end
            references.any? ? { references: references } : {}
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friendly_shipping-0.9.0 lib/friendly_shipping/services/tforce_freight/generate_reference_hash.rb