box_packer 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f008c3a427610279ae4435799857cd9a56365f64
4
- data.tar.gz: 7f04c88fa47c529b0a8f5038bdad6ec01f5525b9
3
+ metadata.gz: 959809e7eac3a76e95054ec7eccbc68e91ad1794
4
+ data.tar.gz: 898284b8f4dfee101bb8df784ed2f26787ef8aa0
5
5
  SHA512:
6
- metadata.gz: 294483a8bfb5b9c1f43556664cccfc2a8e8d3ec2a88e3f26a6934c4e7b07099154bf9b0b652008b03109ecf63032b6217e19dd67e9b129221e69c802a90f892a
7
- data.tar.gz: 8ca0891dbed70a3bdc51ce0d7b55768d6e8525d91b5ff85fb202a36f5d0190b9f131a802417bd125eb2eb26d48ba63d78d888bba45a202ecf3eb6f58211e231a
6
+ metadata.gz: 452b2949f4716224416ebcfe8ca91d56eeb1866086c9edaa638f901f2709ca0d1353f179471d5d462639325a77e52a6fa97fa5e0d6553bed29c8dd57ccea6ddc
7
+ data.tar.gz: d8c849a45ab956d649bea7e2d84db8ce81fba6baee0d196a17ebfe40ed1d9058376ae8955624108610ac372911a61afc65e0539fdb4478bd689afb11a0dca3bc
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ lib/box_packer/test.rb
data/README.md CHANGED
@@ -45,16 +45,18 @@ BoxPacker.container [3, 6, 7] do
45
45
  end
46
46
  ```
47
47
 
48
- With optional labels, weights and packings limit:
48
+ With optional labels, weights, quantity and packings limit:
49
49
 
50
50
  ``` ruby
51
51
  BoxPacker.container [15, 20, 13], label: 'Parcel', weight_limit: 50, packings_limit: 3 do
52
- add_item [2, 3, 5], label: 'Shoes', weight: 47
52
+ add_item [2, 3, 5], label: 'Shoes', weight: 47, quantity: 2
53
53
  add_item [3, 3, 1], label: 'Watch', weight: 24
54
54
  add_item [1, 1, 4], label: 'Bag', weight: 7
55
55
  pack! # returns 2
56
56
 
57
57
  puts self # |Container| Parcel 20x15x13 Weight Limit:50 Packings Limit:3
58
+ # | Packing| Remaining Volume:3870 Remaining Weight:3
59
+ # | Item| Shoes 5x3x2 (0,0,0) Volume:30 Weight:47
58
60
  # | Packing| Remaining Volume:3870 Remaining Weight:3
59
61
  # | Item| Shoes 5x3x2 (0,0,0) Volume:30 Weight:47
60
62
  # | Packing| Remaining Volume:3887 Remaining Weight:19
data/box_packer.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'rake'
22
22
  spec.add_development_dependency 'rspec'
23
23
 
24
- spec.add_dependency 'attr_extras'
25
- spec.add_dependency 'rasem'
24
+ spec.add_dependency 'attr_extras', '~> 3.1.0'
25
+ spec.add_dependency 'rasem', '~> 0.6.0'
26
26
 
27
27
  end
@@ -25,8 +25,11 @@ module BoxPacker
25
25
  self.instance_exec(&b) if block_given?
26
26
  end
27
27
 
28
- def add_item(*args)
29
- items << Item.new(*args)
28
+ def add_item(dimensions, opts={})
29
+ quantity = opts.delete(:quantity) || 1
30
+ quantity.times do
31
+ items << Item.new(dimensions, opts)
32
+ end
30
33
  end
31
34
 
32
35
  def <<(item)
@@ -40,8 +43,11 @@ module BoxPacker
40
43
  def pack!
41
44
  prepare_to_pack!
42
45
  return unless packable?
43
- @packed_successfully = Packer.pack(self)
44
- packings.count
46
+ if @packed_successfully = Packer.pack(self)
47
+ packings.count
48
+ else
49
+ @packings = []
50
+ end
45
51
  end
46
52
 
47
53
  def new_packing!
@@ -56,7 +62,11 @@ module BoxPacker
56
62
  s << " Weight Limit:#{weight_limit}" if weight_limit
57
63
  s << " Packings Limit:#{packings_limit}" if packings_limit
58
64
  s << "\n"
59
- s << (@packings ? @packings : items).map(&:to_s).join
65
+ if packed_successfully
66
+ s << packings.map(&:to_s).join
67
+ else
68
+ s << "| | Did Not Pack!"
69
+ end
60
70
  end
61
71
 
62
72
  def draw!(filename, opts={})
@@ -21,7 +21,7 @@ module BoxPacker
21
21
  private
22
22
 
23
23
  def too_many_packings?
24
- packings.count >= packings_limit - 1 if packings_limit
24
+ packings.count >= packings_limit if packings_limit
25
25
  end
26
26
 
27
27
  def pack_box(possible_items, box)
@@ -1,3 +1,3 @@
1
1
  module BoxPacker
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: box_packer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max White
@@ -56,30 +56,30 @@ dependencies:
56
56
  name: attr_extras
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rasem
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.6.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.6.0
83
83
  description: A Heuristic First-Fit 3D Bin Packing Algorithm with Weight Limit
84
84
  email:
85
85
  - mushishi78@gmail.com