Class: Shipping::CartonLabelGenerator

Inherits:
BaseService show all
Defined in:
app/services/shipping/carton_label_generator.rb

Overview

Service object: carton label generator.

Defined Under Namespace

Classes: Result

Instance Attribute Summary

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#process(shipment, options = {}) ⇒ Result

Returns the generated PDF, shipment, and file name.

Parameters:

  • shipment (Shipment)

    the shipment to label (an SSCC is generated when missing)

  • options (Hash) (defaults to: {})

    rendering options forwarded to Pdf::Label::Carton

Options Hash (options):

  • copies (Integer)

    reserved rendering option forwarded to the label

Returns:

  • (Result)

    the generated PDF, shipment, and file name



13
14
15
16
17
18
19
20
21
22
# File 'app/services/shipping/carton_label_generator.rb', line 13

def process(shipment, options = {})
  # SSCC is a requirement for a carton label, generate it here
  if shipment.container_code.blank?
    shipment.set_sscc
    shipment.save
  end

  pdf = Pdf::Label::Carton.new(shipment, options).call
  Result.new(pdf: pdf, shipment: shipment, file_name: "#{shipment.reference_number}.pdf")
end