Class: BoxPacker::Packer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/box_packer/packer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ Packer

Returns a new instance of Packer.



9
10
11
# File 'lib/box_packer/packer.rb', line 9

def initialize(container)
  @container = container
end

Class Method Details

.pack(container) ⇒ Object



5
6
7
# File 'lib/box_packer/packer.rb', line 5

def self.pack(container)
  new(container).pack
end

Instance Method Details

#packObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/box_packer/packer.rb', line 15

def pack
  @items = container.items.sort_by!(&:volume).reverse!

  until too_many_packings?
    new_packing!
    pack_box(@items, container)
    return true if @items.empty?
  end
  false
end