zebra-zpl 1.0.5 → 1.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +6 -0
- data/README.md +259 -76
- data/docs/example.rb +249 -0
- data/docs/images/barcode.png +0 -0
- data/docs/images/datamatrix.png +0 -0
- data/docs/images/earth.jpg +0 -0
- data/docs/images/graphics.png +0 -0
- data/docs/images/image.png +0 -0
- data/docs/images/image_inverted.png +0 -0
- data/docs/images/images.png +0 -0
- data/docs/images/justification.png +0 -0
- data/docs/images/qrcode.png +0 -0
- data/docs/images/rotation.png +0 -0
- data/docs/images/text.png +0 -0
- data/lib/zebra/print_job.rb +7 -13
- data/lib/zebra/zpl.rb +20 -13
- data/lib/zebra/zpl/barcode.rb +29 -12
- data/lib/zebra/zpl/barcode_type.rb +4 -1
- data/lib/zebra/zpl/box.rb +16 -4
- data/lib/zebra/zpl/comment.rb +15 -0
- data/lib/zebra/zpl/datamatrix.rb +76 -0
- data/lib/zebra/zpl/graphic.rb +91 -0
- data/lib/zebra/zpl/image.rb +91 -0
- data/lib/zebra/zpl/label.rb +2 -13
- data/lib/zebra/zpl/pdf417.rb +50 -0
- data/lib/zebra/zpl/qrcode.rb +2 -2
- data/lib/zebra/zpl/text.rb +44 -20
- data/lib/zebra/zpl/version.rb +1 -1
- data/spec/fixtures/default.jpg +0 -0
- data/spec/spec_helper.rb +6 -2
- data/spec/zebra/print_job_spec.rb +13 -18
- data/spec/zebra/zpl/barcode_spec.rb +70 -63
- data/spec/zebra/zpl/box_spec.rb +27 -31
- data/spec/zebra/zpl/character_set_spec.rb +7 -7
- data/spec/zebra/zpl/comment_spec.rb +18 -0
- data/spec/zebra/zpl/datamatrix_spec.rb +124 -0
- data/spec/zebra/zpl/graphics_spec.rb +227 -0
- data/spec/zebra/zpl/image_spec.rb +113 -0
- data/spec/zebra/zpl/label_spec.rb +40 -52
- data/spec/zebra/zpl/pdf417_spec.rb +108 -0
- data/spec/zebra/zpl/qrcode_spec.rb +92 -92
- data/spec/zebra/zpl/text_spec.rb +57 -55
- data/zebra-zpl.gemspec +14 -15
- metadata +71 -22
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zebra::Zpl::Comment do
|
4
|
+
it "can be initialized with the data" do
|
5
|
+
comment = described_class.new data: "THIS IS A COMMENT"
|
6
|
+
expect(comment.data).to eq "THIS IS A COMMENT"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#to_zpl" do
|
10
|
+
subject(:comment) { described_class.new attributes }
|
11
|
+
let(:attributes) {{
|
12
|
+
data: "THIS IS A COMMENT",
|
13
|
+
}}
|
14
|
+
it "contains the comment" do
|
15
|
+
expect(comment.to_zpl).to eq "^FXTHIS IS A COMMENT^FS"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zebra::Zpl::Datamatrix do
|
4
|
+
it "can be initialized with the symbol height" do
|
5
|
+
datamatrix = described_class.new symbol_height: 3
|
6
|
+
expect(datamatrix.symbol_height).to eq 3
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be initialized with a quality level" do
|
10
|
+
datamatrix = described_class.new quality: 140
|
11
|
+
expect(datamatrix.quality).to eq 140
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can be initialized with a number of columns" do
|
15
|
+
datamatrix = described_class.new columns: 33
|
16
|
+
expect(datamatrix.columns).to eq 33
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can be initialized with a number of rows" do
|
20
|
+
datamatrix = described_class.new rows: 42
|
21
|
+
expect(datamatrix.rows).to eq 42
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can be initialized with a format" do
|
25
|
+
datamatrix = described_class.new format: 2
|
26
|
+
expect(datamatrix.format).to eq 2
|
27
|
+
end
|
28
|
+
it "can be initialized with a aspect ratio" do
|
29
|
+
datamatrix = described_class.new aspect_ratio: 2
|
30
|
+
expect(datamatrix.aspect_ratio).to eq 2
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#orientation" do
|
34
|
+
it "raises an error if the orientation not in [N I R B]" do
|
35
|
+
expect { described_class.new orientation: 'A' }.to raise_error(Zebra::Zpl::Datamatrix::InvalidOrientationError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#quality" do
|
40
|
+
it "raises an error if the quality is not one of 0, 50, 80, 100, 140, 200" do
|
41
|
+
expect { described_class.new quality: 20 }.to raise_error(Zebra::Zpl::Datamatrix::InvalidQualityFactorError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#columns" do
|
46
|
+
it "raises an error if the number of columns is out of bounds" do
|
47
|
+
expect { described_class.new columns: 0 }.to raise_error(Zebra::Zpl::Datamatrix::InvalidSizeError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#rows" do
|
52
|
+
it "raises an error if the number of rows is out of bounds" do
|
53
|
+
expect { described_class.new rows: 59 }.to raise_error(Zebra::Zpl::Datamatrix::InvalidSizeError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
describe "#to_zpl" do
|
59
|
+
let(:valid_attributes) { {
|
60
|
+
position: [50, 50],
|
61
|
+
symbol_height: 5,
|
62
|
+
data: "foobar"
|
63
|
+
}}
|
64
|
+
let(:datamatrix) { described_class.new valid_attributes }
|
65
|
+
let(:tokens) { datamatrix.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
66
|
+
|
67
|
+
it "raises an error if the X position is not given" do
|
68
|
+
datamatrix = described_class.new position: [nil, 50], data: "foobar"
|
69
|
+
expect {
|
70
|
+
datamatrix.to_zpl
|
71
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "raises an error if the Y position is not given" do
|
75
|
+
datamatrix = described_class.new position: [50, nil], data: "foobar"
|
76
|
+
expect {
|
77
|
+
datamatrix.to_zpl
|
78
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises an error if the data to be printed was not informed" do
|
82
|
+
datamatrix.data = nil
|
83
|
+
expect {
|
84
|
+
datamatrix.to_zpl
|
85
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the data to be printed is not given")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raises an error if the scale factor is not given" do
|
89
|
+
valid_attributes.delete :symbol_height
|
90
|
+
|
91
|
+
expect {
|
92
|
+
datamatrix.to_zpl
|
93
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the symbol height to be used is not given")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "contains the barcode command '^B'" do
|
97
|
+
expect(datamatrix.to_zpl).to match /\^B/
|
98
|
+
end
|
99
|
+
|
100
|
+
it "contains the X position" do
|
101
|
+
expect(tokens[2]).to eq "50"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "contains the Y position" do
|
105
|
+
expect(tokens[3]).to eq "50"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "contains Data Matrix code type" do
|
109
|
+
expect(tokens[6]).to eq "^BXN"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "contains the symbol_height" do
|
113
|
+
expect(tokens[7]).to eq "5"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "contains the quality level" do
|
117
|
+
expect(tokens[8]).to eq "200"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "contains the data to be printed in the datamatrix" do
|
121
|
+
expect(tokens[10]).to eq "foobar"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zebra::Zpl::Graphic do
|
4
|
+
it "can be initialized with graphic type" do
|
5
|
+
graphic = described_class.new graphic_type: Zebra::Zpl::Graphic::ELLIPSE
|
6
|
+
expect(graphic.graphic_type).to eq "E"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be initialized with a graphic width" do
|
10
|
+
graphic = described_class.new graphic_width: 30
|
11
|
+
expect(graphic.graphic_width).to eq 30
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can be initialized with a graphic height" do
|
15
|
+
graphic = described_class.new graphic_height: 30
|
16
|
+
expect(graphic.graphic_height).to eq 30
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can be initialized with a line_thickness" do
|
20
|
+
graphic = described_class.new line_thickness: 3
|
21
|
+
expect(graphic.line_thickness).to eq 3
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can be initialized with a color" do
|
25
|
+
graphic = described_class.new color: "W"
|
26
|
+
expect(graphic.color).to eq "W"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can be initialized with an orientation" do
|
30
|
+
graphic = described_class.new orientation: "R"
|
31
|
+
expect(graphic.orientation).to eq "R"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can be initialized with a rounding degree" do
|
35
|
+
graphic = described_class.new rounding_degree: 2
|
36
|
+
expect(graphic.rounding_degree).to eq 2
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
describe "#orientation" do
|
42
|
+
it "raises an error if the orientation not in [N L]" do
|
43
|
+
expect { described_class.new orientation: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidOrientationError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#color" do
|
48
|
+
it "raises an error if the color not in [B W]" do
|
49
|
+
expect { described_class.new color: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidColorError)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#line_thickness" do
|
54
|
+
it "raises an error if line thickness is not a number" do
|
55
|
+
expect { described_class.new line_thickness: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidLineThickness)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#graphic_type" do
|
60
|
+
it "raises an error if the graphic type not in [E B D C S]" do
|
61
|
+
expect { described_class.new graphic_type: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidGraphicType)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#to_zpl" do
|
66
|
+
let(:valid_attributes) { {
|
67
|
+
position: [50, 50],
|
68
|
+
graphic_width: 200,
|
69
|
+
graphic_height: 300,
|
70
|
+
line_thickness: 2,
|
71
|
+
color: "B",
|
72
|
+
orientation: "L",
|
73
|
+
rounding_degree: 3,
|
74
|
+
symbol_type: "C"
|
75
|
+
}}
|
76
|
+
let(:graphic_ellipse) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::ELLIPSE}) }
|
77
|
+
let(:graphic_diagonal) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::DIAGONAL})}
|
78
|
+
let(:graphic_box) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::BOX}) }
|
79
|
+
let(:graphic_symbol) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::SYMBOL}) }
|
80
|
+
let(:graphic_circle) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::CIRCLE}) }
|
81
|
+
|
82
|
+
let(:tokens_ellipse) { graphic_ellipse.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
83
|
+
let(:tokens_diagonal) { graphic_diagonal.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
84
|
+
let(:tokens_box) { graphic_box.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
85
|
+
let(:tokens_symbol) { graphic_symbol.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
86
|
+
let(:tokens_circle) { graphic_circle.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
87
|
+
|
88
|
+
it "raises an error if the X position is not given" do
|
89
|
+
graphic = described_class.new position: [nil, 50], graphic_type: described_class::ELLIPSE
|
90
|
+
expect {
|
91
|
+
graphic.to_zpl
|
92
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "raises an error if the Y position is not given" do
|
96
|
+
graphic = described_class.new position: [50, nil], graphic_type: described_class::ELLIPSE
|
97
|
+
expect {
|
98
|
+
graphic.to_zpl
|
99
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "raises an error if Graphic Type is not given" do
|
103
|
+
graphic = described_class.new position: [50, 50]
|
104
|
+
expect {
|
105
|
+
graphic.to_zpl
|
106
|
+
}.to raise_error(Zebra::Zpl::Graphic::InvalidGraphicType)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "contains the X position" do
|
110
|
+
expect(tokens_ellipse[2]).to eq "50"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "contains the Y position" do
|
114
|
+
expect(tokens_ellipse[3]).to eq "50"
|
115
|
+
end
|
116
|
+
|
117
|
+
#Elipse Attributes
|
118
|
+
|
119
|
+
it "ellipse contains the ellipse graphic command '^GE'" do
|
120
|
+
expect(tokens_ellipse[4]).to eq "^GE"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "ellipse contains the graphic width" do
|
124
|
+
expect(tokens_ellipse[5]).to eq "200"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "ellipse contains the graphic height" do
|
128
|
+
expect(tokens_ellipse[6]).to eq "300"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "ellipse contains the line thickness" do
|
132
|
+
expect(tokens_ellipse[7]).to eq "2"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "ellipse contains the color" do
|
136
|
+
expect(tokens_ellipse[8]).to eq "B"
|
137
|
+
end
|
138
|
+
|
139
|
+
#Box Attributes
|
140
|
+
|
141
|
+
it "box contains the box graphic command '^GB'" do
|
142
|
+
expect(tokens_box[4]).to eq "^GB"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "box contains the graphic width" do
|
146
|
+
expect(tokens_box[5]).to eq "200"
|
147
|
+
end
|
148
|
+
|
149
|
+
it "box contains the graphic height" do
|
150
|
+
expect(tokens_box[6]).to eq "300"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "box contains the line thickness" do
|
154
|
+
expect(tokens_box[7]).to eq "2"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "box contains the color" do
|
158
|
+
expect(tokens_box[8]).to eq "B"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "box contains the rounding degree" do
|
162
|
+
expect(tokens_box[9]).to eq "3"
|
163
|
+
end
|
164
|
+
|
165
|
+
#Circle Attributes
|
166
|
+
|
167
|
+
it "circle contains the circle graphic command '^GC'" do
|
168
|
+
expect(tokens_circle[4]).to eq "^GC"
|
169
|
+
end
|
170
|
+
|
171
|
+
it "circle contains the graphic width" do
|
172
|
+
expect(tokens_circle[5]).to eq "200"
|
173
|
+
end
|
174
|
+
|
175
|
+
it "circle contains the line thickness" do
|
176
|
+
expect(tokens_circle[6]).to eq "2"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "circle contains the color" do
|
180
|
+
expect(tokens_circle[7]).to eq "B"
|
181
|
+
end
|
182
|
+
|
183
|
+
#Diagonal Attributes
|
184
|
+
|
185
|
+
it "diagonal contains the diagonal graphic command '^GD'" do
|
186
|
+
expect(tokens_diagonal[4]).to eq "^GD"
|
187
|
+
end
|
188
|
+
|
189
|
+
it "diagonal contains the graphic width" do
|
190
|
+
expect(tokens_diagonal[5]).to eq "200"
|
191
|
+
end
|
192
|
+
|
193
|
+
it "diagonal contains the graphic width" do
|
194
|
+
expect(tokens_diagonal[6]).to eq "300"
|
195
|
+
end
|
196
|
+
|
197
|
+
it "diagonal contains the line thickness" do
|
198
|
+
expect(tokens_diagonal[7]).to eq "2"
|
199
|
+
end
|
200
|
+
|
201
|
+
it "diagonal contains the color" do
|
202
|
+
expect(tokens_diagonal[8]).to eq "B"
|
203
|
+
end
|
204
|
+
|
205
|
+
it "diagonal contains the orientation" do
|
206
|
+
expect(tokens_diagonal[9]).to eq "L"
|
207
|
+
end
|
208
|
+
|
209
|
+
#Symbol Attributes
|
210
|
+
|
211
|
+
it "symbol contains the symbol graphic command '^GS'" do
|
212
|
+
expect(tokens_symbol[4][0..2]).to eq "^GS"
|
213
|
+
end
|
214
|
+
|
215
|
+
it "symbol contains the graphic height" do
|
216
|
+
expect(tokens_symbol[5]).to eq "300"
|
217
|
+
end
|
218
|
+
|
219
|
+
it "symbol contains the graphic width" do
|
220
|
+
expect(tokens_symbol[6]).to eq "200"
|
221
|
+
end
|
222
|
+
|
223
|
+
it "symbol contains the symbol type" do
|
224
|
+
expect(tokens_symbol[7]).to eq "^FDC"
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zebra::Zpl::Image do
|
4
|
+
|
5
|
+
it 'can be initialized with a path' do
|
6
|
+
img = described_class.new path: 'spec/fixtures/default.jpg'
|
7
|
+
expect(img.path).to match /^(.+)\/([^\/]+)$/
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can be initialized with dimensions (width & height)' do
|
11
|
+
img = described_class.new width: 800, height: 600
|
12
|
+
expect(img.width).to eq 800
|
13
|
+
expect(img.height).to eq 600
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can be initialized with a rotation amount' do
|
17
|
+
img = described_class.new rotation: 90
|
18
|
+
expect(img.rotation).to eq 90
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can be initialized with a black threshold' do
|
22
|
+
img = described_class.new black_threshold: 0.25
|
23
|
+
expect(img.black_threshold).to eq 0.25
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can be initialized with the invert flag' do
|
27
|
+
img = described_class.new invert: true
|
28
|
+
expect(img.invert).to eq true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can be initialized with the compress flag' do
|
32
|
+
img = described_class.new compress: true
|
33
|
+
expect(img.compress).to eq true
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#width' do
|
37
|
+
it 'raises an error if an invalid width is given' do
|
38
|
+
expect { described_class.new width: -10 }.to raise_error(Zebra::Zpl::Image::InvalidSizeError)
|
39
|
+
expect { described_class.new width: 'abc' }.to raise_error(Zebra::Zpl::Image::InvalidSizeError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#height' do
|
44
|
+
it 'raises an error if an invalid height is given' do
|
45
|
+
expect { described_class.new height: -10 }.to raise_error(Zebra::Zpl::Image::InvalidSizeError)
|
46
|
+
expect { described_class.new height: 'abc' }.to raise_error(Zebra::Zpl::Image::InvalidSizeError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#rotation' do
|
51
|
+
it 'raises an error if an invalid rotation value is given' do
|
52
|
+
expect { described_class.new rotation: '90d' }.to raise_error(Zebra::Zpl::Image::InvalidRotationError)
|
53
|
+
expect { described_class.new rotation: 'abc' }.to raise_error(Zebra::Zpl::Image::InvalidRotationError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#black_threshold' do
|
58
|
+
it 'raises an error if an invalid black threshold is given' do
|
59
|
+
expect { described_class.new black_threshold: -5 }.to raise_error(Zebra::Zpl::Image::InvalidThresholdError)
|
60
|
+
expect { described_class.new black_threshold: 1.1 }.to raise_error(Zebra::Zpl::Image::InvalidThresholdError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#to_zpl' do
|
65
|
+
let(:valid_attributes) { {
|
66
|
+
path: 'spec/fixtures/default.jpg',
|
67
|
+
position: [50, 50],
|
68
|
+
width: 100,
|
69
|
+
height: 150
|
70
|
+
}}
|
71
|
+
let(:image) { described_class.new valid_attributes }
|
72
|
+
let(:tokens) { image.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
73
|
+
|
74
|
+
it 'raises an error if the X position is not given' do
|
75
|
+
qrcode = described_class.new position: [nil, 50]
|
76
|
+
expect {
|
77
|
+
qrcode.to_zpl
|
78
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'raises an error if the Y position is not given' do
|
82
|
+
qrcode = described_class.new position: [50, nil]
|
83
|
+
expect {
|
84
|
+
qrcode.to_zpl
|
85
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'raises an error if the path is not given' do
|
89
|
+
valid_attributes.delete :path
|
90
|
+
|
91
|
+
expect {
|
92
|
+
image.to_zpl
|
93
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the path is invalid or not given")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "contains the Graphics Field command '^GF'" do
|
97
|
+
expect(image.to_zpl).to match /\^GF/
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'contains the X position' do
|
101
|
+
expect(tokens[1]).to eq '50'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'contains the Y position' do
|
105
|
+
expect(tokens[2]).to eq '50'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'contains the properly encoded image' do
|
109
|
+
expect(tokens[3..-1].join).to eq '^GFA1079107913:::::M0FR06L0IFQ07K03IFEP0FK07JFO01F8J01KF8N01F8J03KFCN03FCJ07KFEN03FCJ07LFN07FEJ0MF8M07HFJ0MF8M0IFI01MF8L01IF8I01MFCL01IF8I01MFCL03IFCI03MFCL03IFCI03MFCL07IFEI03MFEL0KF:I03MFEK01KF8:I03MFCK03KFCI01MFCK03KFEI01MFCK07KFEI01MFCK0MFJ0MF8K0MFJ0MF8J01MF8J07LFK01MF8J07KFEK03MFCJ03KFCK03MFEJ01KF8K07MFEK0KFL0OFK03IFEL08M01L0IF8L01F8::::::P03MFC:::::::::::::::::::::::::::::::::::^FS'
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|