open-ship 0.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/open-ship.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{open-ship}
5
- s.version = "0.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Nathan Smith"]
9
9
  s.cert_chain = ["/Users/nsmith/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2011-05-05}
10
+ s.date = %q{2011-05-26}
11
11
  s.description = %q{A library to make the hard parts of commercial shipping a little easier.}
12
12
  s.email = %q{nathansmith22@gmail.com}
13
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/openship.rb", "lib/openship/label.rb", "lib/openship/openship.rb", "lib/openship/sscc.rb"]
14
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/openship.rb", "lib/openship/label.rb", "lib/openship/openship.rb", "lib/openship/sscc.rb", "spec/openship/sscc_spec.rb", "spec/spec_helper.rb", "open-ship.gemspec"]
13
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/open-ship.rb", "lib/open-ship/gga4r.rb", "lib/open-ship/gga4r/array_helper.rb", "lib/open-ship/gga4r/gga4r_main.rb", "lib/open-ship/gga4r/version.rb", "lib/open-ship/label.rb", "lib/open-ship/label/carton_label.rb", "lib/open-ship/label/text_label.rb", "lib/open-ship/sortr.rb", "lib/open-ship/sscc.rb"]
14
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/open-ship.rb", "lib/open-ship/gga4r.rb", "lib/open-ship/gga4r/array_helper.rb", "lib/open-ship/gga4r/gga4r_main.rb", "lib/open-ship/gga4r/version.rb", "lib/open-ship/label.rb", "lib/open-ship/label/carton_label.rb", "lib/open-ship/label/text_label.rb", "lib/open-ship/sortr.rb", "lib/open-ship/sscc.rb", "spec/open-ship/carton_spec.rb", "spec/open-ship/label/carton_label_spec.rb", "spec/open-ship/label/text_label_spec.rb", "spec/open-ship/sscc_spec.rb", "spec/spec_helper.rb", "tmp/test_carton_label.pdf", "tmp/test_text_label.pdf", "open-ship.gemspec"]
15
15
  s.homepage = %q{http://open-ship.github.com/open-ship/}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Open-ship", "--main", "README"]
17
17
  s.require_paths = ["lib"]
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenShip::Carton do
4
+
5
+
6
+ describe "When packing a carton" do
7
+
8
+ before(:each) do
9
+ @cart = OpenShip::Carton.new
10
+ @cart.width = 80
11
+ @cart.length = 100
12
+ @cart.height = 30
13
+ @box = OpenShip::Box.new
14
+ @box.width = 12
15
+ @box.length = 14
16
+ @box.height = 10
17
+ @bp = OpenShip::BoxPosition.new
18
+ @pos = OpenShip::Position.new
19
+
20
+ @pos.x = 0
21
+ @pos.y = 0
22
+ @pos.z = 0
23
+ @bp.box = @box
24
+ @bp.position = @pos
25
+
26
+ @box2 = OpenShip::Box.new
27
+ @box2.width = 8
28
+ @box2.length = 7
29
+ @box2.height = 5
30
+
31
+ @bp2 = OpenShip::BoxPosition.new
32
+ @pos2 = OpenShip::Position.new
33
+
34
+ @pos2.x = 12
35
+ @pos2.y = 0
36
+ @pos2.z = 0
37
+ @bp2.box = @box2
38
+ @bp2.position = @pos2
39
+
40
+
41
+ @wide_box = OpenShip::Box.new
42
+ @wide_box.width = 80
43
+ @wide_box.length = 7
44
+ @wide_box.height = 5
45
+
46
+ @wide_flat_box = OpenShip::Box.new
47
+ @wide_flat_box.width = 80
48
+ @wide_flat_box.length = 100
49
+ @wide_flat_box.height = 5
50
+
51
+
52
+ @big_box = OpenShip::Box.new
53
+ @big_box.width = 80
54
+ @big_box.length = 100
55
+ @big_box.height = 30
56
+
57
+ @lamp = OpenShip::Box.new
58
+ @lamp.width = 10
59
+ @lamp.length = 8
60
+ @lamp.height = 6
61
+
62
+ end
63
+
64
+ it "should be able to return its space in square units" do
65
+ space = @cart.get_space
66
+ space.length.should == @cart.volume
67
+ end
68
+
69
+ it "should be able to return its free space in square units if a box is packed in it" do
70
+ @cart.box_positions = []
71
+ @cart.box_positions << @bp
72
+ @cart.box_positions << @bp2
73
+ space = @cart.get_space
74
+ space.length.should == (@cart.volume - @box.volume - @box2.volume)
75
+
76
+ end
77
+
78
+ it "should be able to add boxes" do
79
+ @cart.box_positions = []
80
+ @cart.add_box(@box)
81
+ @cart.add_box(@box2)
82
+ space = @cart.get_space
83
+ space.length.should == (@cart.volume - @box.volume - @box2.volume)
84
+
85
+ end
86
+
87
+
88
+ it "should be able to return a valid position for a box that can fit in it." do
89
+ @cart.box_positions = []
90
+ @cart.box_positions << @bp
91
+ new_position = @cart.position_for_box(@box2)
92
+ new_position.class.should == OpenShip::Position
93
+ # Check that a really long box is moved down the length of the container."
94
+ new_position = @cart.position_for_box(@wide_box)
95
+ new_position.y.should be > 0
96
+ # Check that a really wide, flat box will be loaded on top of existing boxes."
97
+ new_position = @cart.position_for_box(@wide_flat_box)
98
+ new_position.z.should be > 0
99
+ end
100
+
101
+ it "should return a nil position for a box that cannot fit." do
102
+ @cart.box_positions = []
103
+ @cart.box_positions << @bp
104
+ new_position = @cart.position_for_box(@big_box)
105
+ new_position.should == nil
106
+ end
107
+
108
+ it "should be able to calculate a shipment" do
109
+ log = Logger.new(STDOUT)
110
+ log.level = Logger::DEBUG
111
+
112
+ population = []
113
+ boxes_to_stores = {}
114
+ i = 0
115
+ 4.times {
116
+ boxes_to_stores[i.to_s] = []
117
+ 20.times {
118
+ box = OpenShip::Box.new
119
+ box.length = ((rand * 9) + 1).to_i
120
+ box.width = ((rand * 19) + 1).to_i
121
+ box.height = ((rand * 19) + 1).to_i
122
+ boxes_to_stores[i.to_s] << box
123
+ }
124
+ i += 1
125
+ }
126
+ ship = OpenShip::Shipment.new(:logger => log)
127
+ ship.boxes_to_stores = boxes_to_stores
128
+ best_fit = ship.run_ga(5, 10)
129
+
130
+ best_fit.cartons_to_stores.each { |k, v|
131
+ puts "Test"
132
+ v.each { |carton|
133
+ carton.volume.should be > carton.box_positions.sum { |bp| bp.box.volume }
134
+ carton.get_space.length.should == carton.free_space
135
+ }
136
+ }
137
+ end
138
+
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenShip::Label::CartonLabel do
4
+
5
+ it "should generate a valid pdf" do
6
+ cl = OpenShip::Label::CartonLabel.new
7
+ cl.upc = "814434010944"
8
+ cl.product = "cordlets"
9
+ cl.style = "charcoal"
10
+ cl.sku = "CDL-1-4CH"
11
+ cl.quantity = 6
12
+ cl.origin = "made in china"
13
+ doc = cl.to_pdf
14
+ doc.render_file("tmp/test_carton_label.pdf")
15
+ doc.class.should == Prawn::Document
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenShip::Label::TextLabel do
4
+
5
+ it "should generate a valid pdf" do
6
+ cl = OpenShip::Label::TextLabel.new
7
+ cl.address1 = "Friday Afternoon (Distribution Center)"
8
+ cl.address2 = "34234234 Whale Face Rd."
9
+ cl.address3 = "Hamlet, Somewhere 234555"
10
+ cl.address4 = "1-800-BLAHBLAHBLAH"
11
+ cl.sku = "CDL-1-4CH"
12
+ cl.line = 1
13
+ cl.quantity = 6
14
+ cl.total_cartons = "1 of 6"
15
+ cl.po = "D234534"
16
+ doc = cl.to_pdf
17
+ doc.render_file("tmp/test_text_label.pdf")
18
+ doc.class.should == Prawn::Document
19
+ end
20
+
21
+ end
File without changes
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'spec/autorun'
2
2
 
3
- require 'openship'
3
+ require 'open-ship'
4
+
5
+ require 'logger'
4
6
 
5
7
  Spec::Runner.configure do |config|
6
8
 
9
+ #logger = Logger.new(STDOUT)
10
+ #@logger.level = Logger::DEBUG
11
+
7
12
  end
@@ -0,0 +1,398 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Producer <feff0050007200610077006e>
5
+ /Creator <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Pages 3 0 R
10
+ /Type /Catalog
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Count 1
15
+ /Type /Pages
16
+ /Kids [5 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 4411
21
+ >>
22
+ stream
23
+ q
24
+ 14.173 48.189 m
25
+ 14.173 119.055 l
26
+ 16.243 119.055 l
27
+ 16.243 48.189 l
28
+ 14.173 48.189 l
29
+ f
30
+ 18.312 48.189 m
31
+ 18.312 119.055 l
32
+ 20.381 119.055 l
33
+ 20.381 48.189 l
34
+ 18.312 48.189 l
35
+ f
36
+ 22.450 48.189 m
37
+ 22.450 119.055 l
38
+ 24.520 119.055 l
39
+ 24.520 48.189 l
40
+ 22.450 48.189 l
41
+ f
42
+ 26.589 48.189 m
43
+ 26.589 119.055 l
44
+ 28.658 119.055 l
45
+ 28.658 48.189 l
46
+ 26.589 48.189 l
47
+ f
48
+ 30.728 48.189 m
49
+ 30.728 119.055 l
50
+ 36.935 119.055 l
51
+ 36.935 48.189 l
52
+ 30.728 48.189 l
53
+ f
54
+ 43.143 48.189 m
55
+ 43.143 119.055 l
56
+ 49.351 119.055 l
57
+ 49.351 48.189 l
58
+ 43.143 48.189 l
59
+ f
60
+ 55.559 48.189 m
61
+ 55.559 119.055 l
62
+ 57.628 119.055 l
63
+ 57.628 48.189 l
64
+ 55.559 48.189 l
65
+ f
66
+ 59.698 48.189 m
67
+ 59.698 119.055 l
68
+ 65.906 119.055 l
69
+ 65.906 48.189 l
70
+ 59.698 48.189 l
71
+ f
72
+ 72.113 48.189 m
73
+ 72.113 119.055 l
74
+ 74.183 119.055 l
75
+ 74.183 48.189 l
76
+ 72.113 48.189 l
77
+ f
78
+ 76.252 48.189 m
79
+ 76.252 119.055 l
80
+ 78.321 119.055 l
81
+ 78.321 48.189 l
82
+ 76.252 48.189 l
83
+ f
84
+ 80.391 48.189 m
85
+ 80.391 119.055 l
86
+ 86.598 119.055 l
87
+ 86.598 48.189 l
88
+ 80.391 48.189 l
89
+ f
90
+ 88.668 48.189 m
91
+ 88.668 119.055 l
92
+ 90.737 119.055 l
93
+ 90.737 48.189 l
94
+ 88.668 48.189 l
95
+ f
96
+ 96.945 48.189 m
97
+ 96.945 119.055 l
98
+ 99.014 119.055 l
99
+ 99.014 48.189 l
100
+ 96.945 48.189 l
101
+ f
102
+ 101.083 48.189 m
103
+ 101.083 119.055 l
104
+ 103.153 119.055 l
105
+ 103.153 48.189 l
106
+ 101.083 48.189 l
107
+ f
108
+ 105.222 48.189 m
109
+ 105.222 119.055 l
110
+ 111.430 119.055 l
111
+ 111.430 48.189 l
112
+ 105.222 48.189 l
113
+ f
114
+ 117.638 48.189 m
115
+ 117.638 119.055 l
116
+ 119.707 119.055 l
117
+ 119.707 48.189 l
118
+ 117.638 48.189 l
119
+ f
120
+ 121.776 48.189 m
121
+ 121.776 119.055 l
122
+ 127.984 119.055 l
123
+ 127.984 48.189 l
124
+ 121.776 48.189 l
125
+ f
126
+ 134.192 48.189 m
127
+ 134.192 119.055 l
128
+ 140.400 119.055 l
129
+ 140.400 48.189 l
130
+ 134.192 48.189 l
131
+ f
132
+ 142.469 48.189 m
133
+ 142.469 119.055 l
134
+ 148.677 119.055 l
135
+ 148.677 48.189 l
136
+ 142.469 48.189 l
137
+ f
138
+ 150.746 48.189 m
139
+ 150.746 119.055 l
140
+ 152.816 119.055 l
141
+ 152.816 48.189 l
142
+ 150.746 48.189 l
143
+ f
144
+ 159.024 48.189 m
145
+ 159.024 119.055 l
146
+ 161.093 119.055 l
147
+ 161.093 48.189 l
148
+ 159.024 48.189 l
149
+ f
150
+ 163.162 48.189 m
151
+ 163.162 119.055 l
152
+ 165.231 119.055 l
153
+ 165.231 48.189 l
154
+ 163.162 48.189 l
155
+ f
156
+ 171.439 48.189 m
157
+ 171.439 119.055 l
158
+ 173.509 119.055 l
159
+ 173.509 48.189 l
160
+ 171.439 48.189 l
161
+ f
162
+ 179.717 48.189 m
163
+ 179.717 119.055 l
164
+ 181.786 119.055 l
165
+ 181.786 48.189 l
166
+ 179.717 48.189 l
167
+ f
168
+ 183.855 48.189 m
169
+ 183.855 119.055 l
170
+ 190.063 119.055 l
171
+ 190.063 48.189 l
172
+ 183.855 48.189 l
173
+ f
174
+ 192.132 48.189 m
175
+ 192.132 119.055 l
176
+ 198.340 119.055 l
177
+ 198.340 48.189 l
178
+ 192.132 48.189 l
179
+ f
180
+ 200.409 48.189 m
181
+ 200.409 119.055 l
182
+ 202.479 119.055 l
183
+ 202.479 48.189 l
184
+ 200.409 48.189 l
185
+ f
186
+ 208.687 48.189 m
187
+ 208.687 119.055 l
188
+ 210.756 119.055 l
189
+ 210.756 48.189 l
190
+ 208.687 48.189 l
191
+ f
192
+ 212.825 48.189 m
193
+ 212.825 119.055 l
194
+ 214.894 119.055 l
195
+ 214.894 48.189 l
196
+ 212.825 48.189 l
197
+ f
198
+ 221.102 48.189 m
199
+ 221.102 119.055 l
200
+ 227.310 119.055 l
201
+ 227.310 48.189 l
202
+ 221.102 48.189 l
203
+ f
204
+ 229.380 48.189 m
205
+ 229.380 119.055 l
206
+ 235.587 119.055 l
207
+ 235.587 48.189 l
208
+ 229.380 48.189 l
209
+ f
210
+ 241.795 48.189 m
211
+ 241.795 119.055 l
212
+ 243.865 119.055 l
213
+ 243.865 48.189 l
214
+ 241.795 48.189 l
215
+ f
216
+ 245.934 48.189 m
217
+ 245.934 119.055 l
218
+ 248.003 119.055 l
219
+ 248.003 48.189 l
220
+ 245.934 48.189 l
221
+ f
222
+ 250.072 48.189 m
223
+ 250.072 119.055 l
224
+ 252.142 119.055 l
225
+ 252.142 48.189 l
226
+ 250.072 48.189 l
227
+ f
228
+ 254.211 48.189 m
229
+ 254.211 119.055 l
230
+ 260.419 119.055 l
231
+ 260.419 48.189 l
232
+ 254.211 48.189 l
233
+ f
234
+ 266.627 48.189 m
235
+ 266.627 119.055 l
236
+ 268.696 119.055 l
237
+ 268.696 48.189 l
238
+ 266.627 48.189 l
239
+ f
240
+ 270.765 48.189 m
241
+ 270.765 119.055 l
242
+ 276.973 119.055 l
243
+ 276.973 48.189 l
244
+ 270.765 48.189 l
245
+ f
246
+ 283.181 48.189 m
247
+ 283.181 119.055 l
248
+ 289.389 119.055 l
249
+ 289.389 48.189 l
250
+ 283.181 48.189 l
251
+ f
252
+ 291.458 48.189 m
253
+ 291.458 119.055 l
254
+ 293.528 119.055 l
255
+ 293.528 48.189 l
256
+ 291.458 48.189 l
257
+ f
258
+ 14.173 138.898 42.520 42.520 re
259
+ S
260
+
261
+ BT
262
+ 18.9850708661417 167.094677165354 Td
263
+ /F1.0 16 Tf
264
+ [<515459>] TJ
265
+ ET
266
+
267
+
268
+ BT
269
+ 29.8730708661417 147.214803149606 Td
270
+ /F1.0 20 Tf
271
+ [<36>] TJ
272
+ ET
273
+
274
+
275
+ BT
276
+ 62.3622047244095 167.094677165354 Td
277
+ /F1.0 16 Tf
278
+ [<303038313434>] TJ
279
+ ET
280
+
281
+
282
+ BT
283
+ 62.3622047244095 147.214803149606 Td
284
+ /F1.0 20 Tf
285
+ [<3031303934>] TJ
286
+ ET
287
+
288
+
289
+ BT
290
+ 255.625795275591 172.801322834646 Td
291
+ /F1.0 12 Tf
292
+ [<636f72646c657473>] TJ
293
+ ET
294
+
295
+
296
+ BT
297
+ 252.289795275591 158.628094488189 Td
298
+ /F1.0 12 Tf
299
+ [<63686172636f616c>] TJ
300
+ ET
301
+
302
+
303
+ BT
304
+ 234.973795275591 144.454866141732 Td
305
+ /F1.0 12 Tf
306
+ [<43444c2d312d344348>] TJ
307
+ ET
308
+
309
+
310
+ BT
311
+ 124.780511811024 14.079842519685 Td
312
+ /F1.0 10 Tf
313
+ [<6d61646520696e206368696e61>] TJ
314
+ ET
315
+
316
+
317
+ BT
318
+ 35.4330708661417 32.4556850393701 Td
319
+ /F2.0 16 Tf
320
+ <30> Tj
321
+ ET
322
+
323
+
324
+ BT
325
+ 65.1968503937008 32.4556850393701 Td
326
+ /F2.0 16 Tf
327
+ <3038> Tj
328
+ ET
329
+
330
+
331
+ BT
332
+ 104.88188976378 32.4556850393701 Td
333
+ /F2.0 16 Tf
334
+ <3134343334> Tj
335
+ ET
336
+
337
+
338
+ BT
339
+ 182.834645669291 32.4556850393701 Td
340
+ /F2.0 16 Tf
341
+ <3031303934> Tj
342
+ ET
343
+
344
+
345
+ BT
346
+ 259.370078740158 32.4556850393701 Td
347
+ /F2.0 16 Tf
348
+ <34> Tj
349
+ ET
350
+
351
+ Q
352
+
353
+ endstream
354
+ endobj
355
+ 5 0 obj
356
+ << /MediaBox [0 0 311.811023622047 189.92125984252]
357
+ /Type /Page
358
+ /Resources << /Font << /F1.0 6 0 R
359
+ /F2.0 7 0 R
360
+ >>
361
+ /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
362
+ >>
363
+ /Parent 3 0 R
364
+ /Contents 4 0 R
365
+ >>
366
+ endobj
367
+ 6 0 obj
368
+ << /Encoding /WinAnsiEncoding
369
+ /Subtype /Type1
370
+ /Type /Font
371
+ /BaseFont /Helvetica
372
+ >>
373
+ endobj
374
+ 7 0 obj
375
+ << /Encoding /WinAnsiEncoding
376
+ /Subtype /Type1
377
+ /Type /Font
378
+ /BaseFont /Courier
379
+ >>
380
+ endobj
381
+ xref
382
+ 0 8
383
+ 0000000000 65535 f
384
+ 0000000015 00000 n
385
+ 0000000109 00000 n
386
+ 0000000158 00000 n
387
+ 0000000215 00000 n
388
+ 0000004678 00000 n
389
+ 0000004889 00000 n
390
+ 0000004986 00000 n
391
+ trailer
392
+ << /Info 1 0 R
393
+ /Root 2 0 R
394
+ /Size 8
395
+ >>
396
+ startxref
397
+ 5081
398
+ %%EOF