Sha256: 8f657212fac3013ed8ca7694c0c3fba3386a2e5dac74ccc6d993017b4372a81f

Contents?: true

Size: 967 Bytes

Versions: 3

Compression:

Stored size: 967 Bytes

Contents

module Comable
  module Inventory
    class Package
      attr_accessor :stock_location
      attr_accessor :units

      delegate :empty?, :size, :count, to: :units

      def initialize(stock_location)
        @stock_location = stock_location
        @units = []
      end

      def initialize_copy(package)
        super
        self.units = package.units.clone
      end

      def to_shipment
        shipment = Comable::Shipment.new(stock_location: stock_location)
        shipment.shipment_items = build_shipment_items(shipment)
        shipment
      end

      def find(unit)
        units.detect { |u| u == unit }
      end

      def add(unit)
        unit = [unit] unless unit.is_a? Array
        units.concat(unit)
      end

      def remove(unit)
        units.delete(unit)
      end

      private

      def build_shipment_items(shipment)
        units.map do |unit|
          unit.to_shipment_item(shipment)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comable-core-0.7.1 app/models/comable/inventory/package.rb
comable-core-0.7.0 app/models/comable/inventory/package.rb
comable-core-0.7.0.beta2 app/models/comable/inventory/package.rb