zebra-zpl 1.1.2 → 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 -418
- data/docs/example.rb +290 -277
- 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
data/spec/zebra/zpl/text_spec.rb
CHANGED
@@ -1,144 +1,109 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Zebra::Zpl::Text do
|
5
|
-
it "can be initialized with the position of the text to be printed" do
|
6
|
-
text = described_class.new position: [20, 40]
|
7
|
-
expect(text.position).to eq [20,40]
|
8
|
-
expect(text.x).to eq 20
|
9
|
-
expect(text.y).to eq 40
|
10
|
-
end
|
11
|
-
|
12
|
-
it "can be initialized with the text rotation" do
|
13
|
-
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
14
|
-
text = described_class.new rotation: rotation
|
15
|
-
expect(text.rotation).to eq rotation
|
16
|
-
end
|
17
|
-
|
18
|
-
it "can be initialized with the font_size to be used" do
|
19
|
-
font_size = Zebra::Zpl::FontSize::SIZE_1
|
20
|
-
text = described_class.new font_size: font_size
|
21
|
-
expect(text.font_size).to eq font_size
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
expect {
|
62
|
-
|
63
|
-
}.to raise_error(Zebra::Zpl::
|
64
|
-
end
|
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
|
-
it "raises an error if the font_size is not informed" do
|
111
|
-
text = described_class.new position: [100, 100], data: "foobar"
|
112
|
-
expect {
|
113
|
-
text.to_zpl
|
114
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the font_size to be used is not given")
|
115
|
-
end
|
116
|
-
|
117
|
-
it "raises an error if the data to be printed was not informed" do
|
118
|
-
text.data = nil
|
119
|
-
expect {
|
120
|
-
text.to_zpl
|
121
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the data to be printed is not given")
|
122
|
-
end
|
123
|
-
|
124
|
-
it "contains the '^FB' command" do
|
125
|
-
expect(text.to_zpl).to match /\^FB/
|
126
|
-
end
|
127
|
-
|
128
|
-
it "contains the attributes in correct order" do
|
129
|
-
expect(text.to_zpl).to eq '^FWN^CF0,28^CI28^FO100,150^FB,4,,L,^FDfoobar^FS'
|
130
|
-
end
|
131
|
-
|
132
|
-
it "contains the properly duplicated attributes in correct order for bold text" do
|
133
|
-
expect(text_bold.to_zpl).to eq '^FWN^CF0,28^CI28^FO102,150^FB,4,,L,^FDfoobar^FS^FWN^CF0,28^CI28^FO100,152^FB,4,,L,^FDfoobar^FS'
|
134
|
-
end
|
135
|
-
|
136
|
-
# it "assumes 1 as the default horizontal multipler" do
|
137
|
-
# expect(text.to_zpl.split(",")[4].to_i).to eq Zebra::Zpl::HorizontalMultiplier::VALUE_1
|
138
|
-
# end
|
139
|
-
#
|
140
|
-
# it "assumes 1 as the default vertical multiplier" do
|
141
|
-
# expect(text.to_zpl.split(",")[5].to_i).to eq Zebra::Zpl::VerticalMultiplier::VALUE_1
|
142
|
-
# end
|
143
|
-
end
|
144
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Zebra::Zpl::Text do
|
5
|
+
it "can be initialized with the position of the text to be printed" do
|
6
|
+
text = described_class.new position: [20, 40]
|
7
|
+
expect(text.position).to eq [20,40]
|
8
|
+
expect(text.x).to eq 20
|
9
|
+
expect(text.y).to eq 40
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be initialized with the text rotation" do
|
13
|
+
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
14
|
+
text = described_class.new rotation: rotation
|
15
|
+
expect(text.rotation).to eq rotation
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be initialized with the font_size to be used" do
|
19
|
+
font_size = Zebra::Zpl::FontSize::SIZE_1
|
20
|
+
text = described_class.new font_size: font_size
|
21
|
+
expect(text.font_size).to eq font_size
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can be initialized with the data to be printed" do
|
25
|
+
data = "foobar"
|
26
|
+
text = described_class.new data: data
|
27
|
+
expect(text.data).to eq data
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can be initialized with the reverse_print" do
|
31
|
+
text = described_class.new reverse_print: true
|
32
|
+
expect(text.reverse_print).to eq true
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#rotation=" do
|
36
|
+
it "raises an error if the received rotation is invalid" do
|
37
|
+
expect {
|
38
|
+
described_class.new.rotation = 4
|
39
|
+
}.to raise_error(Zebra::Zpl::Rotation::InvalidRotationError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#font_size=" do
|
44
|
+
it "raises an error if the received font_size is invalid" do
|
45
|
+
expect {
|
46
|
+
described_class.new.font_size = -1
|
47
|
+
}.to raise_error(Zebra::Zpl::FontSize::InvalidFontSizeError)
|
48
|
+
expect {
|
49
|
+
described_class.new.font_size = 32001
|
50
|
+
}.to raise_error(Zebra::Zpl::FontSize::InvalidFontSizeError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#to_zpl" do
|
55
|
+
subject(:text) { described_class.new position: [100, 150], font_size: Zebra::Zpl::FontSize::SIZE_3, data: "foobar" }
|
56
|
+
subject(:text_bold) { described_class.new position: [100, 150], font_size: Zebra::Zpl::FontSize::SIZE_3, bold: true, data: "foobar" }
|
57
|
+
subject(:tokens) { text.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
58
|
+
|
59
|
+
it "raises an error if the X position was not informed" do
|
60
|
+
text = described_class.new position: [nil, 100], data: "foobar"
|
61
|
+
expect {
|
62
|
+
text.to_zpl
|
63
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an error if the Y position was not informed" do
|
67
|
+
text = described_class.new position: [100, nil]
|
68
|
+
expect {
|
69
|
+
text.to_zpl
|
70
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "raises an error if the font_size is not informed" do
|
74
|
+
text = described_class.new position: [100, 100], data: "foobar"
|
75
|
+
expect {
|
76
|
+
text.to_zpl
|
77
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the font_size to be used is not given")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "raises an error if the data to be printed was not informed" do
|
81
|
+
text.data = nil
|
82
|
+
expect {
|
83
|
+
text.to_zpl
|
84
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the data to be printed is not given")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "contains the '^FB' command" do
|
88
|
+
expect(text.to_zpl).to match /\^FB/
|
89
|
+
end
|
90
|
+
|
91
|
+
it "contains the attributes in correct order" do
|
92
|
+
expect(text.to_zpl).to eq '^FWN^A0,28^CI28^FO100,150^FB,4,,L,^FDfoobar^FS'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "contains the properly duplicated attributes in correct order for bold text" do
|
96
|
+
expect(text_bold.to_zpl).to eq '^FWN^A0,28^CI28^FO101,150^FB,4,,L,^FDfoobar^FS^FWN^A0,28^CI28^FO100,151^FB,4,,L,^FDfoobar^FS'
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'contains reverse print field on reverse_print mode' do
|
100
|
+
text = described_class.new position: [100, 100], font_size: Zebra::Zpl::FontSize::SIZE_3, data: "foobar", reverse_print: true
|
101
|
+
|
102
|
+
expect(text.to_zpl).to match /\^FR/
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'does not have reverse print field if not specified' do
|
106
|
+
expect(text.to_zpl).to_not match /\^FR/
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zebra-zpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barnabas Bulpett
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-10-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: img2zpl
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|
190
|
-
rubygems_version: 3.
|
190
|
+
rubygems_version: 3.1.6
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: Simple DSL to create labels and send them to a Zebra printer using Ruby,
|