zebra-zpl 1.0.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 +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE +21 -0
- data/LICENSE_ORIGINAL.txt +22 -0
- data/README.md +180 -0
- data/Rakefile +1 -0
- data/lib/zebra/print_job.rb +35 -0
- data/lib/zebra/zpl/barcode.rb +55 -0
- data/lib/zebra/zpl/barcode_type.rb +34 -0
- data/lib/zebra/zpl/box.rb +50 -0
- data/lib/zebra/zpl/character_set.rb +45 -0
- data/lib/zebra/zpl/country_code.rb +36 -0
- data/lib/zebra/zpl/font.rb +47 -0
- data/lib/zebra/zpl/justification.rb +21 -0
- data/lib/zebra/zpl/label.rb +97 -0
- data/lib/zebra/zpl/language.rb +76 -0
- data/lib/zebra/zpl/multipliers.rb +42 -0
- data/lib/zebra/zpl/print_mode.rb +18 -0
- data/lib/zebra/zpl/printable.rb +58 -0
- data/lib/zebra/zpl/qrcode.rb +37 -0
- data/lib/zebra/zpl/rotation.rb +20 -0
- data/lib/zebra/zpl/text.rb +80 -0
- data/lib/zebra/zpl/version.rb +5 -0
- data/lib/zebra/zpl.rb +18 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/zebra/print_job_spec.rb +36 -0
- data/spec/zebra/zpl/barcode_spec.rb +196 -0
- data/spec/zebra/zpl/box_spec.rb +71 -0
- data/spec/zebra/zpl/character_set_spec.rb +100 -0
- data/spec/zebra/zpl/label_spec.rb +138 -0
- data/spec/zebra/zpl/qrcode_spec.rb +101 -0
- data/spec/zebra/zpl/text_spec.rb +139 -0
- data/spec/zebra/zpl/zpl_spec.rb +5 -0
- data/zebra-zpl.gemspec +28 -0
- metadata +174 -0
@@ -0,0 +1,139 @@
|
|
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
|
+
text.position.should == [20,40]
|
8
|
+
text.x.should == 20
|
9
|
+
text.y.should == 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
|
+
text.rotation.should == 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
|
+
text.font_size.should == 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
|
+
text.h_multiplier.should == 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
|
+
text.v_multiplier.should == 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
|
+
text.data.should == 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
|
+
text.print_mode.should == 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 = 6
|
60
|
+
}.to raise_error(Zebra::Zpl::FontSize::InvalidFontSizeError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#h_multiplier=" do
|
65
|
+
it "raises an error if the received multiplier is invalid" do
|
66
|
+
expect {
|
67
|
+
described_class.new.h_multiplier = 9
|
68
|
+
}.to raise_error(Zebra::Zpl::HorizontalMultiplier::InvalidMultiplierError)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#v_multiplier=" do
|
73
|
+
it "raises an error if the received multiplier is invalid" do
|
74
|
+
expect {
|
75
|
+
described_class.new.v_multiplier = 10
|
76
|
+
}.to raise_error(Zebra::Zpl::VerticalMultiplier::InvalidMultiplierError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#print_mode=" do
|
81
|
+
it "raises an error if the received print mode is invalid" do
|
82
|
+
expect {
|
83
|
+
described_class.new.print_mode = "foo"
|
84
|
+
}.to raise_error(Zebra::Zpl::PrintMode::InvalidPrintModeError)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#to_zpl" do
|
89
|
+
subject(:text) { described_class.new :position => [100, 150], :font_size => Zebra::Zpl::FontSize::SIZE_3, :data => "foobar" }
|
90
|
+
|
91
|
+
it "raises an error if the X position was not informed" do
|
92
|
+
text = described_class.new :position => [nil, 100], :data => "foobar"
|
93
|
+
expect {
|
94
|
+
text.to_zpl
|
95
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "raises an error if the Y position was not informed" do
|
99
|
+
text = described_class.new :position => [100, nil]
|
100
|
+
expect {
|
101
|
+
text.to_zpl
|
102
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "raises an error if the font_size is not informed" do
|
106
|
+
text = described_class.new :position => [100, 100], :data => "foobar"
|
107
|
+
expect {
|
108
|
+
text.to_zpl
|
109
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the font_size to be used is not given")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "raises an error if the data to be printed was not informed" do
|
113
|
+
text.data = nil
|
114
|
+
expect {
|
115
|
+
text.to_zpl
|
116
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the data to be printed is not given")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "begins width the 'A' command" do
|
120
|
+
text.to_zpl.should =~ /\AA/
|
121
|
+
end
|
122
|
+
|
123
|
+
it "assumes 1 as the default horizontal multipler" do
|
124
|
+
text.to_zpl.split(",")[4].to_i.should == Zebra::Zpl::HorizontalMultiplier::VALUE_1
|
125
|
+
end
|
126
|
+
|
127
|
+
it "assumes 1 as the default vertical multiplier" do
|
128
|
+
text.to_zpl.split(",")[5].to_i.should == Zebra::Zpl::VerticalMultiplier::VALUE_1
|
129
|
+
end
|
130
|
+
|
131
|
+
it "assumes the normal print mode as the default" do
|
132
|
+
text.to_zpl.split(",")[6].should == Zebra::Zpl::PrintMode::NORMAL
|
133
|
+
end
|
134
|
+
|
135
|
+
it "assumes no rotation by default" do
|
136
|
+
text.to_zpl.split(",")[2].to_i.should == Zebra::Zpl::Rotation::NO_ROTATION
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/zebra-zpl.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zebra/zpl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zebra-zpl"
|
8
|
+
spec.version = Zebra::Zpl::VERSION
|
9
|
+
spec.authors = ["Barnabas Bulpett"]
|
10
|
+
spec.email = ["barnabasbulpett@gmail.com"]
|
11
|
+
spec.description = %q{Print labels using ZPL2 and Ruby}
|
12
|
+
spec.summary = %q{Simple DSL to create labels and send them to a Zebra printer using Ruby, ZPL2 and CUPS}
|
13
|
+
spec.homepage = "https://github.com/bbulpett/zebra-zpl"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "cups"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zebra-zpl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Barnabas Bulpett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cups
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Print labels using ZPL2 and Ruby
|
98
|
+
email:
|
99
|
+
- barnabasbulpett@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- Gemfile
|
107
|
+
- Guardfile
|
108
|
+
- LICENSE
|
109
|
+
- LICENSE_ORIGINAL.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/zebra/print_job.rb
|
113
|
+
- lib/zebra/zpl.rb
|
114
|
+
- lib/zebra/zpl/barcode.rb
|
115
|
+
- lib/zebra/zpl/barcode_type.rb
|
116
|
+
- lib/zebra/zpl/box.rb
|
117
|
+
- lib/zebra/zpl/character_set.rb
|
118
|
+
- lib/zebra/zpl/country_code.rb
|
119
|
+
- lib/zebra/zpl/font.rb
|
120
|
+
- lib/zebra/zpl/justification.rb
|
121
|
+
- lib/zebra/zpl/label.rb
|
122
|
+
- lib/zebra/zpl/language.rb
|
123
|
+
- lib/zebra/zpl/multipliers.rb
|
124
|
+
- lib/zebra/zpl/print_mode.rb
|
125
|
+
- lib/zebra/zpl/printable.rb
|
126
|
+
- lib/zebra/zpl/qrcode.rb
|
127
|
+
- lib/zebra/zpl/rotation.rb
|
128
|
+
- lib/zebra/zpl/text.rb
|
129
|
+
- lib/zebra/zpl/version.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/zebra/print_job_spec.rb
|
132
|
+
- spec/zebra/zpl/barcode_spec.rb
|
133
|
+
- spec/zebra/zpl/box_spec.rb
|
134
|
+
- spec/zebra/zpl/character_set_spec.rb
|
135
|
+
- spec/zebra/zpl/label_spec.rb
|
136
|
+
- spec/zebra/zpl/qrcode_spec.rb
|
137
|
+
- spec/zebra/zpl/text_spec.rb
|
138
|
+
- spec/zebra/zpl/zpl_spec.rb
|
139
|
+
- zebra-zpl.gemspec
|
140
|
+
homepage: https://github.com/bbulpett/zebra-zpl
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.5.1
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Simple DSL to create labels and send them to a Zebra printer using Ruby,
|
164
|
+
ZPL2 and CUPS
|
165
|
+
test_files:
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
- spec/zebra/print_job_spec.rb
|
168
|
+
- spec/zebra/zpl/barcode_spec.rb
|
169
|
+
- spec/zebra/zpl/box_spec.rb
|
170
|
+
- spec/zebra/zpl/character_set_spec.rb
|
171
|
+
- spec/zebra/zpl/label_spec.rb
|
172
|
+
- spec/zebra/zpl/qrcode_spec.rb
|
173
|
+
- spec/zebra/zpl/text_spec.rb
|
174
|
+
- spec/zebra/zpl/zpl_spec.rb
|