Class: BoxPacker::Container
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#label ⇒ Object
Returns the value of attribute label.
-
#packed_successfully ⇒ Object
readonly
Returns the value of attribute packed_successfully.
-
#packing ⇒ Object
readonly
Returns the value of attribute packing.
-
#packings ⇒ Object
readonly
Returns the value of attribute packings.
-
#packings_limit ⇒ Object
Returns the value of attribute packings_limit.
-
#weight_limit ⇒ Object
Returns the value of attribute weight_limit.
Attributes inherited from Box
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #add_item(dimensions, opts = {}) ⇒ Object
- #draw!(filename, opts = {}) ⇒ Object
-
#initialize(dimensions, opts = {}, &b) ⇒ Container
constructor
A new instance of Container.
- #new_packing! ⇒ Object
- #pack! ⇒ Object
- #to_s ⇒ Object
Methods inherited from Box
Constructor Details
#initialize(dimensions, opts = {}, &b) ⇒ Container
Returns a new instance of Container.
17 18 19 20 21 22 23 24 25 |
# File 'lib/box_packer/container.rb', line 17 def initialize(dimensions, opts = {}, &b) super(Dimensions[*dimensions]) @label = opts[:label] @weight_limit = opts[:weight_limit] @packings_limit = opts[:packings_limit] @items = opts[:items] || [] orient! instance_exec(&b) if b end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
15 16 17 |
# File 'lib/box_packer/container.rb', line 15 def items @items end |
#label ⇒ Object
Returns the value of attribute label.
14 15 16 |
# File 'lib/box_packer/container.rb', line 14 def label @label end |
#packed_successfully ⇒ Object (readonly)
Returns the value of attribute packed_successfully.
15 16 17 |
# File 'lib/box_packer/container.rb', line 15 def packed_successfully @packed_successfully end |
#packing ⇒ Object (readonly)
Returns the value of attribute packing.
15 16 17 |
# File 'lib/box_packer/container.rb', line 15 def packing @packing end |
#packings ⇒ Object (readonly)
Returns the value of attribute packings.
15 16 17 |
# File 'lib/box_packer/container.rb', line 15 def packings @packings end |
#packings_limit ⇒ Object
Returns the value of attribute packings_limit.
14 15 16 |
# File 'lib/box_packer/container.rb', line 14 def packings_limit @packings_limit end |
#weight_limit ⇒ Object
Returns the value of attribute weight_limit.
14 15 16 |
# File 'lib/box_packer/container.rb', line 14 def weight_limit @weight_limit end |
Instance Method Details
#<<(item) ⇒ Object
34 35 36 |
# File 'lib/box_packer/container.rb', line 34 def <<(item) items << item.dup end |
#add_item(dimensions, opts = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/box_packer/container.rb', line 27 def add_item(dimensions, opts = {}) quantity = opts.delete(:quantity) || 1 quantity.times do items << Item.new(dimensions, opts) end end |
#draw!(filename, opts = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/box_packer/container.rb', line 68 def draw!(filename, opts = {}) exporter = SVGExporter.new(self, opts) exporter.draw exporter.save(filename) end |
#new_packing! ⇒ Object
53 54 55 56 |
# File 'lib/box_packer/container.rb', line 53 def new_packing! @packing = Packing.new(volume, weight_limit) @packings << @packing end |
#pack! ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/box_packer/container.rb', line 42 def pack! prepare_to_pack! return unless packable? if @packed_successfully = Packer.pack(self) packings.count else @packings = [] false end end |
#to_s ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/box_packer/container.rb', line 58 def to_s s = "\n|Container|" s << " #{label}" if label s << " #{dimensions}" s << " Weight Limit:#{weight_limit}" if weight_limit s << " Packings Limit:#{packings_limit}" if packings_limit s << "\n" s << (packed_successfully ? packings.map(&:to_s).join : '| | Did Not Pack!') end |