zebra-zpl 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +79 -71
- data/README.md +442 -439
- data/docs/example.rb +290 -290
- data/lib/zebra/zpl/barcode.rb +124 -72
- data/lib/zebra/zpl/barcode_type.rb +38 -37
- data/lib/zebra/zpl/font.rb +48 -47
- data/lib/zebra/zpl/graphic.rb +93 -91
- data/lib/zebra/zpl/label.rb +89 -86
- data/lib/zebra/zpl/text.rb +82 -104
- data/lib/zebra/zpl/version.rb +5 -5
- data/spec/zebra/zpl/barcode_spec.rb +270 -203
- data/spec/zebra/zpl/image_spec.rb +146 -146
- data/spec/zebra/zpl/label_spec.rb +110 -126
- data/spec/zebra/zpl/text_spec.rb +109 -144
- metadata +3 -3
@@ -1,203 +1,270 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Zebra::Zpl::Barcode do
|
4
|
-
it "can be initialized with the position of the text to be printed" do
|
5
|
-
barcode = described_class.new position: [20, 40]
|
6
|
-
expect(barcode.position).to eq [20,40]
|
7
|
-
expect(barcode.x).to eq 20
|
8
|
-
expect(barcode.y).to eq 40
|
9
|
-
end
|
10
|
-
|
11
|
-
it "can be initialized with the barcode rotation" do
|
12
|
-
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
13
|
-
barcode = described_class.new rotation: rotation
|
14
|
-
expect(barcode.rotation).to eq rotation
|
15
|
-
end
|
16
|
-
|
17
|
-
it "can be initialized with the barcode rotation" do
|
18
|
-
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
19
|
-
barcode = described_class.new rotation: rotation
|
20
|
-
expect(barcode.rotation).to eq rotation
|
21
|
-
end
|
22
|
-
|
23
|
-
it "can be initialized with the barcode type" do
|
24
|
-
type = Zebra::Zpl::BarcodeType::CODE_128_AUTO
|
25
|
-
barcode = described_class.new type: type
|
26
|
-
expect(barcode.type).to eq type
|
27
|
-
end
|
28
|
-
|
29
|
-
it "can be initialized with the barcode width" do
|
30
|
-
barcode = described_class.new width: 5
|
31
|
-
expect(barcode.width).to eq 5
|
32
|
-
end
|
33
|
-
|
34
|
-
it "can be initialized with the barcode height" do
|
35
|
-
barcode = described_class.new height: 20
|
36
|
-
expect(barcode.height).to eq 20
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can be initialized with the ratio" do
|
40
|
-
barcode = described_class.new ratio: 3.0
|
41
|
-
expect(barcode.ratio).to eq 3.0
|
42
|
-
end
|
43
|
-
|
44
|
-
it "can be initialized with the narrow bar width" do
|
45
|
-
barcode = described_class.new narrow_bar_width: 3
|
46
|
-
expect(barcode.narrow_bar_width).to eq 3
|
47
|
-
end
|
48
|
-
|
49
|
-
it "can be initialized with the wide bar width" do
|
50
|
-
barcode = described_class.new wide_bar_width: 10
|
51
|
-
expect(barcode.wide_bar_width).to eq 10
|
52
|
-
end
|
53
|
-
|
54
|
-
it "can be initialized informing if the human readable code should be printed" do
|
55
|
-
barcode = described_class.new print_human_readable_code: true
|
56
|
-
expect(barcode.print_human_readable_code).to eq true
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
expect {
|
150
|
-
barcode.to_zpl
|
151
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the
|
152
|
-
end
|
153
|
-
|
154
|
-
it "
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
|
-
it "
|
171
|
-
expect(tokens[
|
172
|
-
end
|
173
|
-
|
174
|
-
it "contains the
|
175
|
-
expect(tokens[
|
176
|
-
end
|
177
|
-
|
178
|
-
it "contains the
|
179
|
-
expect(tokens[
|
180
|
-
end
|
181
|
-
|
182
|
-
it "contains the
|
183
|
-
expect(tokens[
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
expect(tokens[
|
192
|
-
end
|
193
|
-
|
194
|
-
it "contains the
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
expect(tokens[
|
201
|
-
|
202
|
-
|
203
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zebra::Zpl::Barcode do
|
4
|
+
it "can be initialized with the position of the text to be printed" do
|
5
|
+
barcode = described_class.new position: [20, 40]
|
6
|
+
expect(barcode.position).to eq [20,40]
|
7
|
+
expect(barcode.x).to eq 20
|
8
|
+
expect(barcode.y).to eq 40
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can be initialized with the barcode rotation" do
|
12
|
+
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
13
|
+
barcode = described_class.new rotation: rotation
|
14
|
+
expect(barcode.rotation).to eq rotation
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can be initialized with the barcode rotation" do
|
18
|
+
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
19
|
+
barcode = described_class.new rotation: rotation
|
20
|
+
expect(barcode.rotation).to eq rotation
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can be initialized with the barcode type" do
|
24
|
+
type = Zebra::Zpl::BarcodeType::CODE_128_AUTO
|
25
|
+
barcode = described_class.new type: type
|
26
|
+
expect(barcode.type).to eq type
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can be initialized with the barcode width" do
|
30
|
+
barcode = described_class.new width: 5
|
31
|
+
expect(barcode.width).to eq 5
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can be initialized with the barcode height" do
|
35
|
+
barcode = described_class.new height: 20
|
36
|
+
expect(barcode.height).to eq 20
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can be initialized with the ratio" do
|
40
|
+
barcode = described_class.new ratio: 3.0
|
41
|
+
expect(barcode.ratio).to eq 3.0
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can be initialized with the narrow bar width" do
|
45
|
+
barcode = described_class.new narrow_bar_width: 3
|
46
|
+
expect(barcode.narrow_bar_width).to eq 3
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can be initialized with the wide bar width" do
|
50
|
+
barcode = described_class.new wide_bar_width: 10
|
51
|
+
expect(barcode.wide_bar_width).to eq 10
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can be initialized informing if the human readable code should be printed" do
|
55
|
+
barcode = described_class.new print_human_readable_code: true
|
56
|
+
expect(barcode.print_human_readable_code).to eq true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can be initialized informing if the human readable code should be printed above" do
|
60
|
+
barcode = described_class.new print_text_above: true
|
61
|
+
expect(barcode.print_text_above).to eq true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can be initialized with the barcode mode" do
|
65
|
+
barcode = described_class.new mode: 'U'
|
66
|
+
expect(barcode.mode).to eq 'U'
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#rotation=" do
|
70
|
+
it "raises an error if the received rotation is invalid" do
|
71
|
+
expect {
|
72
|
+
described_class.new.rotation = 4
|
73
|
+
}.to raise_error(Zebra::Zpl::Rotation::InvalidRotationError)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#type=" do
|
78
|
+
it "raises an error if the received type is invalid" do
|
79
|
+
expect {
|
80
|
+
described_class.new.type = "ZZZ"
|
81
|
+
}.to raise_error(Zebra::Zpl::BarcodeType::InvalidBarcodeTypeError)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#narrow_bar_width=" do
|
86
|
+
it "raises an error if the type is Code 128 and the width is invalid" do
|
87
|
+
expect {
|
88
|
+
described_class.new type: Zebra::Zpl::BarcodeType::CODE_128_AUTO, narrow_bar_width: 20
|
89
|
+
}.to raise_error(Zebra::Zpl::Barcode::InvalidNarrowBarWidthError)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#wide_bar_width=" do
|
94
|
+
it "raises an error if the type is Code 128 and the width is invalid" do
|
95
|
+
expect {
|
96
|
+
described_class.new type: Zebra::Zpl::BarcodeType::CODE_128_AUTO, wide_bar_width: 40
|
97
|
+
}.to raise_error(Zebra::Zpl::Barcode::InvalidWideBarWidthError)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#print_human_readable_code" do
|
102
|
+
it "defaults to false" do
|
103
|
+
expect(described_class.new.print_human_readable_code).to eq false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#print_text_above" do
|
108
|
+
it "defaults to false" do
|
109
|
+
expect(described_class.new.print_text_above).to eq false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#to_zpl" do
|
114
|
+
let(:valid_attributes) { {
|
115
|
+
position: [100, 150],
|
116
|
+
type: Zebra::Zpl::BarcodeType::CODE_128_AUTO,
|
117
|
+
height: 20,
|
118
|
+
width: 5,
|
119
|
+
narrow_bar_width: 3,
|
120
|
+
wide_bar_width: 6,
|
121
|
+
data: "foobar"
|
122
|
+
} }
|
123
|
+
let(:barcode) { described_class.new valid_attributes }
|
124
|
+
let(:tokens) { barcode.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
125
|
+
|
126
|
+
it "raises an error if the X position was not informed" do
|
127
|
+
barcode = described_class.new position: [nil, 100], data: "foobar"
|
128
|
+
expect {
|
129
|
+
barcode.to_zpl
|
130
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
131
|
+
end
|
132
|
+
|
133
|
+
it "raises an error if the Y position was not informed" do
|
134
|
+
barcode = described_class.new position: [100, nil]
|
135
|
+
expect {
|
136
|
+
barcode.to_zpl
|
137
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "raises an error if the barcode type is not informed" do
|
141
|
+
barcode = described_class.new position: [100, 100], data: "foobar"
|
142
|
+
expect {
|
143
|
+
barcode.to_zpl
|
144
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the barcode type to be used is not given")
|
145
|
+
end
|
146
|
+
|
147
|
+
it "raises an error if the data to be printed was not informed" do
|
148
|
+
barcode.data = nil
|
149
|
+
expect {
|
150
|
+
barcode.to_zpl
|
151
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the data to be printed is not given")
|
152
|
+
end
|
153
|
+
|
154
|
+
it "raises an error if the height to be used was not informed" do
|
155
|
+
barcode.height = nil
|
156
|
+
expect {
|
157
|
+
barcode.to_zpl
|
158
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the height to be used is not given")
|
159
|
+
end
|
160
|
+
|
161
|
+
it "raises an error if the neither of with, narrow_bar_width, or wide_bar_width are not given" do
|
162
|
+
valid_attributes.delete :width
|
163
|
+
valid_attributes.delete :narrow_bar_width
|
164
|
+
valid_attributes.delete :wide_bar_width
|
165
|
+
expect {
|
166
|
+
barcode.to_zpl
|
167
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the width to be used is not given")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "begins with the command 'B'" do
|
171
|
+
expect(tokens[4]).to eq '^BY'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "contains the X position" do
|
175
|
+
expect(tokens[2]).to eq '100'
|
176
|
+
end
|
177
|
+
|
178
|
+
it "contains the Y position" do
|
179
|
+
expect(tokens[3]).to eq '150'
|
180
|
+
end
|
181
|
+
|
182
|
+
it "contains the width" do
|
183
|
+
expect(tokens[5]).to eq '5'
|
184
|
+
end
|
185
|
+
|
186
|
+
it "contains the ratio" do
|
187
|
+
expect(tokens[6]).to eq '2.0'
|
188
|
+
end
|
189
|
+
|
190
|
+
it "contains the barcode height" do
|
191
|
+
expect(tokens[7]).to eq '20'
|
192
|
+
end
|
193
|
+
|
194
|
+
it "contains the barcode type" do
|
195
|
+
expect(tokens[8]).to start_with "^B#{Zebra::Zpl::BarcodeType::CODE_128_AUTO}"
|
196
|
+
end
|
197
|
+
|
198
|
+
it "contains the barcode rotation" do
|
199
|
+
expect(tokens[0]).to start_with '^FW'
|
200
|
+
expect(tokens[0]).to end_with Zebra::Zpl::Rotation::NO_ROTATION.to_s
|
201
|
+
expect(tokens[8]).to start_with '^B'
|
202
|
+
expect(tokens[8]).to end_with Zebra::Zpl::Rotation::NO_ROTATION.to_s
|
203
|
+
end
|
204
|
+
|
205
|
+
it "contains the correct indication when the human readable code should be printed" do
|
206
|
+
valid_attributes.merge! print_human_readable_code: true
|
207
|
+
expect(tokens[9]).to eq 'Y'
|
208
|
+
end
|
209
|
+
|
210
|
+
it "contains the correct indication when the human readable code should not be printed" do
|
211
|
+
valid_attributes.merge! print_human_readable_code: false
|
212
|
+
expect(tokens[9]).to eq 'N'
|
213
|
+
end
|
214
|
+
|
215
|
+
it "contains the correct indication when the human readable code should be printed above or below" do
|
216
|
+
valid_attributes.merge! print_text_above: true
|
217
|
+
expect(tokens[10]).to eq 'Y'
|
218
|
+
end
|
219
|
+
|
220
|
+
it "contains the correct indication when the human readable code should not be printed above or below" do
|
221
|
+
valid_attributes.merge! print_text_above: false
|
222
|
+
expect(tokens[10]).to eq 'N'
|
223
|
+
end
|
224
|
+
|
225
|
+
it "contains the correct indication of a mode in barcode" do
|
226
|
+
valid_attributes.merge! mode: 'U'
|
227
|
+
expect(tokens[11]).to eq 'U'
|
228
|
+
end
|
229
|
+
|
230
|
+
it "contains the data to be printed in the barcode" do
|
231
|
+
expect(tokens[12]).to eq 'foobar'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "#to_zpl with CODE_39" do
|
236
|
+
let(:valid_attributes) { {
|
237
|
+
position: [100, 150],
|
238
|
+
type: Zebra::Zpl::BarcodeType::CODE_39,
|
239
|
+
height: 20,
|
240
|
+
width: 5,
|
241
|
+
narrow_bar_width: 3,
|
242
|
+
wide_bar_width: 6,
|
243
|
+
print_human_readable_code: true,
|
244
|
+
print_text_above: true,
|
245
|
+
data: "foobar"
|
246
|
+
} }
|
247
|
+
let(:barcode) { described_class.new valid_attributes }
|
248
|
+
|
249
|
+
it "contains the barcode type" do
|
250
|
+
expect(barcode.to_zpl).to end_with "^B#{Zebra::Zpl::BarcodeType::CODE_39}N,,,Y,Y^FDfoobar^FS"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "#to_zpl with CODE_UPS_MAXICODE" do
|
255
|
+
let(:valid_attributes) { {
|
256
|
+
position: [100, 150],
|
257
|
+
type: Zebra::Zpl::BarcodeType::CODE_UPS_MAXICODE,
|
258
|
+
height: 20,
|
259
|
+
width: 5,
|
260
|
+
narrow_bar_width: 3,
|
261
|
+
wide_bar_width: 6,
|
262
|
+
data: "foobar"
|
263
|
+
} }
|
264
|
+
let(:barcode) { described_class.new valid_attributes }
|
265
|
+
|
266
|
+
it "contains the barcode type" do
|
267
|
+
expect(barcode.to_zpl).to end_with "^B#{Zebra::Zpl::BarcodeType::CODE_UPS_MAXICODE}^FDfoobar^FS"
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|