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.
@@ -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
- # it "can be initialized with the horizontal multiplier" do
25
- # multiplier = Zebra::Zpl::HorizontalMultiplier::VALUE_1
26
- # text = described_class.new h_multiplier: multiplier
27
- # expect(text.h_multiplier).to eq multiplier
28
- # end
29
- #
30
- # it "can be initialized with the vertical multiplier" do
31
- # multiplier = Zebra::Zpl::VerticalMultiplier::VALUE_1
32
- # text = described_class.new v_multiplier: multiplier
33
- # expect(text.v_multiplier).to eq multiplier
34
- # end
35
-
36
- it "can be initialized with the data to be printed" do
37
- data = "foobar"
38
- text = described_class.new data: data
39
- expect(text.data).to eq data
40
- end
41
-
42
- it "can be initialized with the printing mode" do
43
- print_mode = Zebra::Zpl::PrintMode::REVERSE
44
- text = described_class.new print_mode: print_mode
45
- expect(text.print_mode).to eq print_mode
46
- end
47
-
48
- describe "#rotation=" do
49
- it "raises an error if the received rotation is invalid" do
50
- expect {
51
- described_class.new.rotation = 4
52
- }.to raise_error(Zebra::Zpl::Rotation::InvalidRotationError)
53
- end
54
- end
55
-
56
- describe "#font_size=" do
57
- it "raises an error if the received font_size is invalid" do
58
- expect {
59
- described_class.new.font_size = -1
60
- }.to raise_error(Zebra::Zpl::FontSize::InvalidFontSizeError)
61
- expect {
62
- described_class.new.font_size = 32001
63
- }.to raise_error(Zebra::Zpl::FontSize::InvalidFontSizeError)
64
- end
65
- end
66
-
67
- # describe "#h_multiplier=" do
68
- # it "raises an error if the received multiplier is invalid" do
69
- # expect {
70
- # described_class.new.h_multiplier = 9
71
- # }.to raise_error(Zebra::Zpl::HorizontalMultiplier::InvalidMultiplierError)
72
- # end
73
- # end
74
- #
75
- # describe "#v_multiplier=" do
76
- # it "raises an error if the received multiplier is invalid" do
77
- # expect {
78
- # described_class.new.v_multiplier = 10
79
- # }.to raise_error(Zebra::Zpl::VerticalMultiplier::InvalidMultiplierError)
80
- # end
81
- # end
82
-
83
- describe "#print_mode=" do
84
- it "raises an error if the received print mode is invalid" do
85
- expect {
86
- described_class.new.print_mode = "foo"
87
- }.to raise_error(Zebra::Zpl::PrintMode::InvalidPrintModeError)
88
- end
89
- end
90
-
91
- describe "#to_zpl" do
92
- subject(:text) { described_class.new position: [100, 150], font_size: Zebra::Zpl::FontSize::SIZE_3, data: "foobar" }
93
- subject(:text_bold) { described_class.new position: [100, 150], font_size: Zebra::Zpl::FontSize::SIZE_3, bold: true, data: "foobar" }
94
- subject(:tokens) { text.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
95
-
96
- it "raises an error if the X position was not informed" do
97
- text = described_class.new position: [nil, 100], data: "foobar"
98
- expect {
99
- text.to_zpl
100
- }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
101
- end
102
-
103
- it "raises an error if the Y position was not informed" do
104
- text = described_class.new position: [100, nil]
105
- expect {
106
- text.to_zpl
107
- }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
108
- end
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.2
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: 2020-02-25 00:00:00.000000000 Z
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.0.6
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,