Class: FriendlyShipping::StructureOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/structure_options.rb

Overview

Options for structures (pallets, skids, etc) in a shipment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(structure_id:, package_options: [], package_options_class: PackageOptions) ⇒ StructureOptions

Returns a new instance of StructureOptions.

Parameters:

  • structure_id (Object)

    unique identifier for this set of options

  • package_options (Array<PackageOptions>) (defaults to: [])

    the options for packages in this structure

  • package_options_class (Class) (defaults to: PackageOptions)

    the class to use for package options when none are provided



12
13
14
15
16
17
18
19
20
# File 'lib/friendly_shipping/structure_options.rb', line 12

def initialize(
  structure_id:,
  package_options: [],
  package_options_class: PackageOptions
)
  @structure_id = structure_id
  @package_options = package_options
  @package_options_class = package_options_class
end

Instance Attribute Details

#structure_idObject (readonly)

Returns unique identifier for this set of options.

Returns:

  • (Object)

    unique identifier for this set of options



7
8
9
# File 'lib/friendly_shipping/structure_options.rb', line 7

def structure_id
  @structure_id
end

Instance Method Details

#options_for_package(package) ⇒ PackageOptions

Parameters:

  • package (#id)

    the package for which to get options

Returns:



24
25
26
27
28
# File 'lib/friendly_shipping/structure_options.rb', line 24

def options_for_package(package)
  package_options.detect do |package_option|
    package_option.package_id == package.id
  end || package_options_class.new(package_id: nil)
end