zebra-epl 0.0.7 → 0.0.8
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.
- data/Guardfile +1 -1
- data/README.md +138 -2
- data/lib/zebra/epl.rb +1 -1
- data/lib/zebra/epl/qrcode.rb +37 -0
- data/lib/zebra/epl/version.rb +1 -1
- data/spec/zebra/epl/qrcode_spec.rb +101 -0
- metadata +7 -4
data/Guardfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
guard 'rspec' do
|
4
|
+
guard 'rspec', cmd: "bundle exec rspec" do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
7
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Zebra::Epl
|
2
2
|
|
3
|
-
|
3
|
+
Zebra::Epl offers a Ruby DSL to design and print labels using the EPL programming language.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,143 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Building labels
|
22
|
+
|
23
|
+
You create new labels with an instance of the `Zebra::Epl::Label` class. It accepts the following options:
|
24
|
+
|
25
|
+
* `copies`: The number of copies to print. This option defaults to 1.
|
26
|
+
* `width`: The label's width, in dots.
|
27
|
+
* `length`: The label's length, is dots.
|
28
|
+
* `gap`: The gap between labels, in dots.
|
29
|
+
* `print_speed`: The print speed to be used. You can use values between 0 and 6. This option is required.
|
30
|
+
* `print_density`: The print density to be used. You can use values between 0 and 15. This option is required.
|
31
|
+
|
32
|
+
With a label, you can start adding elements to it:
|
33
|
+
|
34
|
+
label = Zebra::Epl::Label.new :print_density => 8, :print_speed => 3
|
35
|
+
text = Zebra::Epl::Text.new :data => "Hello, printer!", :position => [100, 100], :font => Zebra::Epl::Font::SIZE_2
|
36
|
+
label << text
|
37
|
+
|
38
|
+
You can add as many elements as you want.
|
39
|
+
|
40
|
+
### Printing the labels
|
41
|
+
|
42
|
+
You need to have your printer visible to CUPS. Once your printer is configured and you know its name on CUPS, you can send the labels to the printer using a `Zebra::PrintJob` instance.
|
43
|
+
|
44
|
+
label = Zebra::Epl::Label.new(
|
45
|
+
:width => 200,
|
46
|
+
:length => 200,
|
47
|
+
:print_speed => 3,
|
48
|
+
:print_density => 6
|
49
|
+
)
|
50
|
+
|
51
|
+
|
52
|
+
barcode = Zebra::Epl::Barcode.new(
|
53
|
+
:data => "12345678",
|
54
|
+
:position => [50, 50],
|
55
|
+
:height => 50,
|
56
|
+
:print_human_readable_code => true,
|
57
|
+
:narrow_bar_width => 4,
|
58
|
+
:wide_bar_width => 8,
|
59
|
+
:type => Zebra::Epl::BarcodeType::CODE_128_AUTO
|
60
|
+
)
|
61
|
+
|
62
|
+
print_job = Zebra::PrintJob.new "your-printer-name-on-cups"
|
63
|
+
|
64
|
+
print_job.print label
|
65
|
+
|
66
|
+
This will persist the label contents to a tempfile (using Ruby's tempfile core library) and copy the file to the printer using either `lpr -P <your-printer-name-on-cups> -o raw <path-to-the-temp-file>` (if you're on Mac OSX) or `lp -d <your-printer-name-on-cups> -o raw <path-to-the-tempfile>` (if you're on Linux). All the tempfile creation/path resolution, as well as which command has to be used, are handled by the `PrintJob` class.
|
67
|
+
|
68
|
+
### Printing QR codes
|
69
|
+
|
70
|
+
label = Zebra::Epl::Label.new(
|
71
|
+
:width=>350,
|
72
|
+
:length=>250,
|
73
|
+
:print_speed=>3,
|
74
|
+
:print_density=>6
|
75
|
+
)
|
76
|
+
|
77
|
+
qrcode = Zebra::Epl::Qrcode.new(
|
78
|
+
:data=>"www.github.com",
|
79
|
+
:position=>[50,10],
|
80
|
+
:scale_factor=>3,
|
81
|
+
:correction_level=>"H"
|
82
|
+
)
|
83
|
+
|
84
|
+
label << qrcode
|
85
|
+
|
86
|
+
print_job = Zebra::PrintJob.new "your-qr-printer-name-on-cups"
|
87
|
+
|
88
|
+
print_job.print label
|
89
|
+
|
90
|
+
### Available elements
|
91
|
+
|
92
|
+
#### Text
|
93
|
+
|
94
|
+
You create text elements to print using instances of the `Zebra::Epl::Text` class. It accepts the following options:
|
95
|
+
|
96
|
+
* `position`: An array with the coordinates to place the text, in dots.
|
97
|
+
* `rotation`: The rotation for the text. More about the possible values below.
|
98
|
+
* `data`: The text to be printed.
|
99
|
+
* `v_multiplier`: The vertical multiplier to use.
|
100
|
+
* `h_multiplier`: The horizontal multipler to use.
|
101
|
+
* `print_mode`: The print mode. Can be normal ("N") or reverse ("R").
|
102
|
+
* `font`: The font size to use. You can use values between 1 and 5.
|
103
|
+
|
104
|
+
For the print modes, you can also use the constants:
|
105
|
+
|
106
|
+
* `Zebra::Epl::PrintMode::NORMAL`
|
107
|
+
* `Zebra::Epl::PrintMode::REVERSE`
|
108
|
+
|
109
|
+
|
110
|
+
#### Barcodes
|
111
|
+
|
112
|
+
You create barcode elements to print using instances of the `Zebra::Epl::Barcode` class. It accepts the following options:
|
113
|
+
|
114
|
+
* `position`: An array with the coordinates to place the text, in dots.
|
115
|
+
* `height`: The barcode's height, in dots.
|
116
|
+
* `rotation`: The rotation for the text. More about the possible values below.
|
117
|
+
* `data`: The text to be printed.
|
118
|
+
* `type`: The type os barcode to use. More on the available types below.
|
119
|
+
* `narrow_bar_width`: The barcode's narrow bar width, in dots.
|
120
|
+
* `wide_bar_width`: The barcode's wide bar width, in dots.
|
121
|
+
* `print_human_readable_code`: Can be `true` or `false`, indicates if the human readable contents should be printed below the barcode.
|
122
|
+
|
123
|
+
The available barcode types are:
|
124
|
+
|
125
|
+
* `Zebra::Epl::BarcodeType::CODE_39`
|
126
|
+
* `Zebra::Epl::BarcodeType::CODE_39_CHECK_DIGIT`
|
127
|
+
* `Zebra::Epl::BarcodeType::CODE_93`
|
128
|
+
* `Zebra::Epl::BarcodeType::CODE_128_AUTO`
|
129
|
+
* `Zebra::Epl::BarcodeType::CODE_128_A`
|
130
|
+
* `Zebra::Epl::BarcodeType::CODE_128_B`
|
131
|
+
* `Zebra::Epl::BarcodeType::CODE_128_C`
|
132
|
+
* `Zebra::Epl::BarcodeType::CODABAR`
|
133
|
+
|
134
|
+
#### QR Codes
|
135
|
+
|
136
|
+
You can create QR Codes elements to print using instances of the `Zebra::Epl::Qrcode` class. It accepts the following options:
|
137
|
+
|
138
|
+
* `position`: An array with the coordinates to place the QR code, in dots.
|
139
|
+
* `scale factor`: Crucial variable of the QR codes's size. Accepted values: 1-99.
|
140
|
+
* `error correction level`: Algorithm enables reading damaged QR codes. There are four error correction levels: L - 7% of codewords can be restored, M - 15% can be restored, Q - 25% can be restored, H - 30% can be restored.
|
141
|
+
|
142
|
+
#### Boxes
|
143
|
+
|
144
|
+
You can draw boxes in your labels:
|
145
|
+
|
146
|
+
box = Zebra::Epl::Box.new :position => [20, 20], :end_position => [100, 100], :line_thickness => 39
|
147
|
+
|
148
|
+
#### Elements rotation
|
149
|
+
|
150
|
+
All printable elements can be rotated on the label, using the `:rotation` option. The accepted rotation values are:
|
151
|
+
|
152
|
+
* `Zebra::Epl::Rotation::NO_ROTATION`: will not rotate the element.
|
153
|
+
* `Zebra::Epl::Rotation::DEGREES_90`: will rotate the element 90 degrees.
|
154
|
+
* `Zebra::Epl::Rotation::DEGREES_180`: will rotate the element 180 degrees.
|
155
|
+
* `Zebra::Epl::Rotation::DEGREES_270`: will rotate the element 270 degrees.
|
156
|
+
|
157
|
+
|
22
158
|
|
23
159
|
## Contributing
|
24
160
|
|
data/lib/zebra/epl.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "zebra/epl/printable"
|
2
|
+
|
3
|
+
module Zebra
|
4
|
+
module Epl
|
5
|
+
class Qrcode
|
6
|
+
include Printable
|
7
|
+
|
8
|
+
class InvalidScaleFactorError < StandardError; end
|
9
|
+
class InvalidCorrectionLevelError < StandardError; end
|
10
|
+
|
11
|
+
attr_reader :scale_factor, :correction_level
|
12
|
+
|
13
|
+
def scale_factor=(value)
|
14
|
+
raise InvalidScaleFactorError unless (1..99).include?(value.to_i)
|
15
|
+
@scale_factor = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def correction_level=(value)
|
19
|
+
raise InvalidCorrectionLevelError unless %w[L M Q H].include?(value.to_s)
|
20
|
+
@correction_level = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_epl
|
24
|
+
check_attributes
|
25
|
+
["b#{x}", y, "Q", "s#{scale_factor}", "e#{correction_level}", "\"#{data}\""].join(",")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def check_attributes
|
31
|
+
super
|
32
|
+
raise MissingAttributeError.new("the scale factor to be used is not given") unless @scale_factor
|
33
|
+
raise MissingAttributeError.new("the error correction level to be used is not given") unless @correction_level
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/zebra/epl/version.rb
CHANGED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zebra::Epl::Qrcode do
|
4
|
+
it "can be initialized with the scale factor" do
|
5
|
+
qrcode = described_class.new :scale_factor => 3
|
6
|
+
expect(qrcode.scale_factor).to eq 3
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be initialized with the error correction level" do
|
10
|
+
qrcode = described_class.new :correction_level => "M"
|
11
|
+
expect(qrcode.correction_level).to eq "M"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#scale_factor" do
|
15
|
+
it "raises an error if the scale factor is not within the range 1-99" do
|
16
|
+
expect{described_class.new :scale_factor=>100}.to raise_error(Zebra::Epl::Qrcode::InvalidScaleFactorError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#correction_level" do
|
21
|
+
it "raises an error if the error correction_level not in [LMQH]" do
|
22
|
+
expect{described_class.new :correction_level=>"A"}.to raise_error(Zebra::Epl::Qrcode::InvalidCorrectionLevelError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#to_epl" do
|
27
|
+
let(:valid_attributes) { {
|
28
|
+
:position => [50, 50],
|
29
|
+
:scale_factor => 3,
|
30
|
+
:correction_level => "M",
|
31
|
+
:data => "foobar"
|
32
|
+
}}
|
33
|
+
let(:qrcode) { described_class.new valid_attributes }
|
34
|
+
let(:tokens) { qrcode.to_epl.split(",") }
|
35
|
+
|
36
|
+
it "raises an error if the X position is not given" do
|
37
|
+
qrcode = described_class.new :position => [nil, 50], :data => "foobar"
|
38
|
+
expect {
|
39
|
+
qrcode.to_epl
|
40
|
+
}.to raise_error(Zebra::Epl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error if the Y position is not given" do
|
44
|
+
qrcode = described_class.new :position => [50, nil], :data => "foobar"
|
45
|
+
expect {
|
46
|
+
qrcode.to_epl
|
47
|
+
}.to raise_error(Zebra::Epl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "raises an error if the data to be printed was not informed" do
|
51
|
+
qrcode.data = nil
|
52
|
+
expect {
|
53
|
+
qrcode.to_epl
|
54
|
+
}.to raise_error(Zebra::Epl::Printable::MissingAttributeError, "Can't print if the data to be printed is not given")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises an error if the scale factor is not given" do
|
58
|
+
valid_attributes.delete :scale_factor
|
59
|
+
|
60
|
+
expect {
|
61
|
+
qrcode.to_epl
|
62
|
+
}.to raise_error(Zebra::Epl::Printable::MissingAttributeError, "Can't print if the scale factor to be used is not given")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises an error if the correction level is not given" do
|
66
|
+
valid_attributes.delete :correction_level
|
67
|
+
|
68
|
+
expect {
|
69
|
+
qrcode.to_epl
|
70
|
+
}.to raise_error(Zebra::Epl::Printable::MissingAttributeError, "Can't print if the error correction level to be used is not given")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "begins with the command 'b'" do
|
74
|
+
qrcode.to_epl.should =~ /\Ab/
|
75
|
+
end
|
76
|
+
|
77
|
+
it "contains the X position" do
|
78
|
+
tokens[0].match(/b(\d+)/)[1].should eq "50"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "contains the Y position" do
|
82
|
+
tokens[1].should eq "50"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "contains QR code type" do
|
86
|
+
tokens[2].should eq "Q"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "contains the scale factor" do
|
90
|
+
tokens[3].should eq "s3"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "contains the error correction level" do
|
94
|
+
tokens[4].should eq "eM"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "contains the data to be printed in the qrcode" do
|
98
|
+
tokens[5].should eq "\"foobar\""
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zebra-epl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cups
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/zebra/epl/multipliers.rb
|
134
134
|
- lib/zebra/epl/print_mode.rb
|
135
135
|
- lib/zebra/epl/printable.rb
|
136
|
+
- lib/zebra/epl/qrcode.rb
|
136
137
|
- lib/zebra/epl/rotation.rb
|
137
138
|
- lib/zebra/epl/text.rb
|
138
139
|
- lib/zebra/epl/version.rb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- spec/zebra/epl/character_set_spec.rb
|
144
145
|
- spec/zebra/epl/epl_spec.rb
|
145
146
|
- spec/zebra/epl/label_spec.rb
|
147
|
+
- spec/zebra/epl/qrcode_spec.rb
|
146
148
|
- spec/zebra/epl/text_spec.rb
|
147
149
|
- spec/zebra/print_job_spec.rb
|
148
150
|
- zebra-epl.gemspec
|
@@ -161,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
163
|
segments:
|
162
164
|
- 0
|
163
165
|
version: '0'
|
164
|
-
hash:
|
166
|
+
hash: 196605653010155924
|
165
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
168
|
none: false
|
167
169
|
requirements:
|
@@ -170,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
172
|
segments:
|
171
173
|
- 0
|
172
174
|
version: '0'
|
173
|
-
hash:
|
175
|
+
hash: 196605653010155924
|
174
176
|
requirements: []
|
175
177
|
rubyforge_project:
|
176
178
|
rubygems_version: 1.8.24
|
@@ -185,5 +187,6 @@ test_files:
|
|
185
187
|
- spec/zebra/epl/character_set_spec.rb
|
186
188
|
- spec/zebra/epl/epl_spec.rb
|
187
189
|
- spec/zebra/epl/label_spec.rb
|
190
|
+
- spec/zebra/epl/qrcode_spec.rb
|
188
191
|
- spec/zebra/epl/text_spec.rb
|
189
192
|
- spec/zebra/print_job_spec.rb
|