Sha256: c455ac5ffd1ad8f819f8867dcbb995b1a3b92c6ff7bc345616cfb3b9888e9cef
Contents?: true
Size: 937 Bytes
Versions: 2
Compression:
Stored size: 937 Bytes
Contents
# frozen_string_literal: true module Physical class Package attr_reader :container, :items, :void_fill_density, :id def initialize(id: nil, container: Physical::Box.new, items: [], void_fill_density: 0, void_fill_density_unit: :g) @id = id || SecureRandom.uuid @void_fill_density = Measured::Weight(void_fill_density, void_fill_density_unit) @container = container @items = Set[*items] end def <<(item) @items.add(item) end def >>(item) @items.delete(item) end def weight container.weight + items.map(&:weight).reduce(&:+) + void_fill_weight end def remaining_volume container.volume - items.map(&:volume).reduce(&:+) end def void_fill_weight return Measured::Weight(0, :g) if container.volume.value.infinite? Measured::Weight(void_fill_density.value * remaining_volume.value, void_fill_density.unit) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
physical-0.1.1 | lib/physical/package.rb |
physical-0.1.0 | lib/physical/package.rb |