open-ship 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v0.1.5. added a big label
1
2
  v0.1.4. made 0 on company prefix not required.
2
3
  v0.1.3. fixed bug in the sscc check digit
3
4
  v0.1.2. added classes for sorting shipments
data/Manifest CHANGED
@@ -9,14 +9,17 @@ lib/open-ship/gga4r/array_helper.rb
9
9
  lib/open-ship/gga4r/gga4r_main.rb
10
10
  lib/open-ship/gga4r/version.rb
11
11
  lib/open-ship/label.rb
12
+ lib/open-ship/label/big_carton_label.rb
12
13
  lib/open-ship/label/carton_label.rb
13
14
  lib/open-ship/label/text_label.rb
14
15
  lib/open-ship/sortr.rb
15
16
  lib/open-ship/sscc.rb
16
17
  spec/open-ship/carton_spec.rb
18
+ spec/open-ship/label/big_carton_label_spec.rb
17
19
  spec/open-ship/label/carton_label_spec.rb
18
20
  spec/open-ship/label/text_label_spec.rb
19
21
  spec/open-ship/sscc_spec.rb
20
22
  spec/spec_helper.rb
23
+ tmp/test_big_carton_label.pdf
21
24
  tmp/test_carton_label.pdf
22
25
  tmp/test_text_label.pdf
@@ -0,0 +1,209 @@
1
+ require 'prawn'
2
+ require 'prawn/measurement_extensions'
3
+ require 'barby'
4
+ require 'barby/outputter/prawn_outputter'
5
+
6
+ module OpenShip
7
+ module Label
8
+
9
+ class BigCartonLabel < CartonLabel
10
+
11
+ attr_accessor :from1, :from2, :from3, :to1, :to2, :to3, :bol, :scac,
12
+ :tracking, :zip, :po_number, :vendor_number, :facility_code, :store_number, :sscc
13
+
14
+ def self.to_pdf(cl, filename)
15
+
16
+ Prawn::Document.generate(filename, :page_size => [4.in, 6.6.in],
17
+ :right_margin => 0.0.cm,
18
+ :left_margin => 0.0.cm,
19
+ :top_margin => 0.0.cm,
20
+ :bottom_margin => 0.0.cm,
21
+ :page_layout => :portrait) do
22
+
23
+
24
+ # Field A
25
+ bounding_box [0,6.6.in], :width => 1.75.in, :height => 1.in do
26
+ indent(5) do
27
+ move_down 5
28
+ self.font_size = 12
29
+ text "FROM:"
30
+ end
31
+ indent(10) do
32
+ move_down 5
33
+ self.font_size = 8
34
+ text cl.from1
35
+ text cl.from2
36
+ text cl.from3
37
+ end
38
+ stroke_bounds
39
+ end
40
+
41
+ # Field B
42
+ bounding_box [1.75.in,6.6.in], :width => 2.25.in, :height => 1.in do
43
+ indent(5) do
44
+ move_down 5
45
+ self.font_size = 12
46
+ text "TO:"
47
+ end
48
+ indent(10) do
49
+ move_down 5
50
+ self.font_size = 12
51
+ text cl.to1
52
+ text cl.to2
53
+ text cl.to3
54
+ end
55
+
56
+ stroke_bounds
57
+ end
58
+
59
+ # Field C
60
+ bounding_box [0.in,5.6.in], :width => 1.5.in, :height => 1.in do
61
+ indent(5) do
62
+ move_down 5
63
+ self.font_size = 12
64
+ text "CARRIER INFO:"
65
+ end
66
+
67
+ indent(10) do
68
+ move_down 5
69
+ self.font_size = 10
70
+ if cl.bol
71
+ text "B/L: #{cl.bol}"
72
+ end
73
+ if cl.scac
74
+ text "SCAC: #{cl.scac}"
75
+ end
76
+ if cl.tracking
77
+ text "PRO: #{cl.tracking}"
78
+ end
79
+ end
80
+
81
+
82
+ stroke_bounds
83
+ end
84
+
85
+ # Field D
86
+ bounding_box [1.5.in,5.6.in], :width => 2.5.in, :height => 1.in do
87
+ if cl.zip.nil?
88
+ raise "Zip must not be nil!"
89
+ end
90
+ the_zip = ("420" + cl.zip.to_s)
91
+ indent(5) do
92
+ move_down 5
93
+ self.font_size = 12
94
+ text "POSTAL ZIP:"
95
+ end
96
+
97
+ indent(10) do
98
+ self.font_size = 12
99
+ text the_zip
100
+ end
101
+
102
+ barcode = Barby::Code128A.new(the_zip)
103
+
104
+ barcode.annotate_pdf(self, {:x => 10, :y => 5, :xdim => 0.010.in, :height => 0.5.in})
105
+
106
+
107
+
108
+ stroke_bounds
109
+ end
110
+
111
+ # Field E
112
+ bounding_box [0.in,4.6.in], :width => 4.in, :height => 1.in do
113
+ indent(100) do
114
+ move_down 20
115
+ self.font_size = 12
116
+ text "PO Number: #{cl.po_number}"
117
+ if cl.vendor_number
118
+ text ("Vendor Number: " + cl.vendor_number.to_s)
119
+ end
120
+ end
121
+
122
+ barcode = Barby::Code128A.new(cl.po_number)
123
+
124
+ barcode.annotate_pdf(self, {:x => 10, :y => 20, :xdim => 0.010.in, :height => 0.5.in})
125
+
126
+ stroke_bounds
127
+ end
128
+
129
+ # Field F
130
+ bounding_box [0.in,3.6.in], :width => 4.in, :height => 1.in do
131
+
132
+ indent(10) do
133
+ move_down 10
134
+ self.font_size = 12
135
+ if cl.quantity
136
+ text "QTY: #{cl.quantity}"
137
+ end
138
+ if cl.upc
139
+ text "UPC: #{cl.upc}"
140
+ barcode = Barby::Code128A.new(cl.upc)
141
+
142
+ barcode.annotate_pdf(self, {:x => 130, :y => 20, :xdim => 0.010.in, :height => 0.5.in})
143
+
144
+ end
145
+ if cl.style
146
+ text "Description: #{cl.style}"
147
+ end
148
+ end
149
+
150
+ stroke_bounds
151
+ end
152
+
153
+ # Field G
154
+ bounding_box [0.in,2.6.in], :width => 2.5.in, :height => 1.in do
155
+ stroke_bounds
156
+ end
157
+
158
+ # Field H
159
+ bounding_box [2.5.in,2.6.in], :width => 1.5.in, :height => 1.in do
160
+
161
+ indent(5) do
162
+ move_down 5
163
+ self.font_size = 12
164
+ text "STORE:"
165
+ end
166
+ indent(10) do
167
+ move_down 10
168
+ self.font_size = 16
169
+ text(("<b>" + cl.store_number.to_s + "</b>"), :inline_format => true)
170
+ end
171
+
172
+
173
+ stroke_bounds
174
+ end
175
+
176
+ # Field I
177
+ bounding_box [0.in,1.6.in], :width => 4.in, :height => 1.6.in do
178
+
179
+ indent(5) do
180
+ move_down(5)
181
+ self.font_size = 10
182
+ text "SSCC-18"
183
+ end
184
+
185
+ indent(60) do
186
+ move_down 5
187
+ self.font_size = 12
188
+ text ("(00) " + cl.sscc)
189
+ end
190
+
191
+ barcode = Barby::GS1128.new(cl.sscc, "A", "00")
192
+
193
+ barcode.annotate_pdf(self, {:x => 40, :y => 5, :xdim => 0.010.in, :height => 1.in})
194
+
195
+ stroke_bounds
196
+ end
197
+
198
+
199
+
200
+ end
201
+
202
+ end
203
+
204
+
205
+ end
206
+
207
+ end
208
+ end
209
+
@@ -50,7 +50,8 @@ module OpenShip
50
50
  check_digit.to_s
51
51
  end
52
52
 
53
- def self.generate_sscc_id(serial_reference)
53
+ def self.generate_sscc_id(serial_reference, opts = {})
54
+ include_prefix = opts[:include_prefix]||false
54
55
  if company_prefix.nil?
55
56
  raise "Company prefix cannot be nil. Set with OpenShip::Sscc.company_prefix"
56
57
  end
@@ -59,7 +60,12 @@ module OpenShip
59
60
  end
60
61
  sequence = @extension_digit + @company_prefix + serial_reference
61
62
  check_digit = self.generate_check_digit(sequence)
62
- sscc = sequence + check_digit
63
+ if !include_prefix
64
+ sscc = sequence + check_digit
65
+ else
66
+ sscc = ("00" + sequence + check_digit)
67
+ end
68
+ sscc
63
69
  end
64
70
 
65
71
 
data/lib/open-ship.rb CHANGED
@@ -9,5 +9,6 @@ require 'open-ship/sortr'
9
9
  require 'open-ship/label'
10
10
  require 'open-ship/label/carton_label'
11
11
  require 'open-ship/label/text_label'
12
+ require 'open-ship/label/big_carton_label'
12
13
  require 'open-ship/gga4r'
13
14
 
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.4"
5
+ s.version = "0.1.5"
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-27}
10
+ s.date = %q{2011-06-02}
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/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"]
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/big_carton_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/big_carton_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/big_carton_label_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_big_carton_label.pdf", "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,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenShip::Label::CartonLabel do
4
+
5
+ it "should generate a valid pdf" do
6
+ cl = OpenShip::Label::BigCartonLabel.new
7
+ cl.from1 = "Some Company"
8
+ cl.from2 = "234 Warehouse St"
9
+ cl.from3 = "Somewhere, NY 11201"
10
+ cl.to1 = "Big Retailer #11243"
11
+ cl.to2 = "123 Retail Road"
12
+ cl.to3 = "New York, NY 10012"
13
+ cl.tracking = "TBD"
14
+ cl.scac = "FDE"
15
+ cl.zip = "956502222"
16
+ cl.po_number = "GL32454"
17
+ cl.vendor_number = "236622"
18
+ cl.upc = "814434010944"
19
+ cl.product = "cordlets"
20
+ cl.style = "charcoal"
21
+ cl.sku = "CDL-1-4CH"
22
+ cl.quantity = 6
23
+ cl.store_number = "2222"
24
+ OpenShip::Sscc.company_prefix = "8144301"
25
+ cl.sscc = OpenShip::Sscc.generate_sscc_id("1234", :include_prefix => false)
26
+ doc = OpenShip::Label::BigCartonLabel.to_pdf(cl, "tmp/test_big_carton_label.pdf")
27
+ doc.class.should == File
28
+ end
29
+
30
+ end