easy-box-packer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/easy-box-packer.rb +26 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c160200ca99944f6560dca5948ce785bde238d87
4
- data.tar.gz: 7d7cd114d8c6ebb74ad5fea4c5974210c2348143
3
+ metadata.gz: 8fdf9c87fb9465a372621274314c24d467848dcc
4
+ data.tar.gz: 328700b5ffd7860761c832d43ade508b01749cac
5
5
  SHA512:
6
- metadata.gz: 4351a0c2f6a572d90e803e2218bc25f9d9e1635ca6d94f1b699b86656bdb34f77ecce108e76b97eea4dbebba49ba03741c36d64a1da10e39dea9628a10a38e00
7
- data.tar.gz: 66c2d2b3a04c2b8e0b1ac1347f8fde974051bf75d06b79f2fac54642a9f76845c8d0af56c7ea7137c22bc73834c3fd8ec0746cd8e09c8a99b24920a55b4a91a6
6
+ metadata.gz: 181a58237b38d18dd3672e01aa66bc93583de44c3be03258e9505edec538c9ab58d529a60dea4a7ff9dd4155747d008507baa9d475a13dfd62f942f0f0e8f54c
7
+ data.tar.gz: ffbf053c8ac2aa0213f32df3b4c8a87276f15ab7159dcfa6fe63d71a44fc88e92790422d3b2fdcbff3a9008a0682341b8b46747f7c0396cb50a2d6d6323cebaf
data/easy-box-packer.rb CHANGED
@@ -139,5 +139,31 @@ module EasyBoxPacker
139
139
  }
140
140
  ]
141
141
  end
142
+
143
+ def find_smallest_container(items:)
144
+ array_of_lwh = items.map { |i| i[:dimensions].sort.reverse }
145
+ items_max_length = array_of_lwh.max { |x, y| x[0] <=> y[0] }[0]
146
+ items_max_width = array_of_lwh.max { |x, y| x[1] <=> y[1] }[1]
147
+ items_min_height = array_of_lwh.max { |x, y| x[2] <=> y[2] }[2]
148
+ items_total_height = array_of_lwh.inject(0) { |sum, x| sum + x[2] }.round(1)
149
+ miminum_box = {}
150
+ (items_min_height..items_total_height.ceil).step(0.1).to_a.bsearch do |i|
151
+ packing = pack(
152
+ container: { dimensions: [items_max_length, items_max_width, i] },
153
+ items: array_of_lwh.map { |a| { dimensions: a }})
154
+
155
+ if packing[:packings].size == 1
156
+ miminum_box = {
157
+ length: items_max_length,
158
+ width: items_max_width,
159
+ height: i
160
+ }
161
+ true
162
+ else
163
+ false
164
+ end
165
+ end
166
+ miminum_box
167
+ end
142
168
  end
143
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-box-packer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aloha Chen