easyzpl 0.0.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f853f7876d8290992a2f82381b54137a2b0e075
4
- data.tar.gz: 6571c5eadb48bd59efc9d256dcf43b85de7ca9ba
3
+ metadata.gz: 0b81e4c749aa17a2e9734d74765102aa527fbdab
4
+ data.tar.gz: fc024aafd5ac34ee63a5138c02f65d7b8cd0306a
5
5
  SHA512:
6
- metadata.gz: 3422308cb9db0d797425cc9c0da98acba974e64dd277494690a4f0f544fe342ba20088666b67c731699dd35df0832feab3b11c502ac1080609da027bea0adeb8
7
- data.tar.gz: f580da3ef59fbc0d83ae92449a26e59d39bb9b2679f29f4b1e496d4bfb4f61e707119adcc7cfbca08daf251ff2a27cdeb9ff60c9df142703cb018fba75f66956
6
+ metadata.gz: 74d5fb8f62b747631a7919c0da2ec3bcc57b4d221fa017bfa525c25c1a051250a1919b4297dbc8e073257953284461fe7828440ee45875e969f4b582e3341833
7
+ data.tar.gz: 7125f9c186fdb766595fa446dbd37856bc64c73cace11059e0a243d4a644e804f1e6426c691616c38451c0d2a43a9bd4528c32186fec319c9302b5b1e4134fa2
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+ - jruby-19mode # JRuby in 1.9 mode
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 TODO: Write your name
1
+ Copyright (c) 2014 Matthew Grigajtis
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Easyzpl
2
+ [![Build Status](https://travis-ci.org/mgrigajtis/easyzpl.svg?branch=master)](https://travis-ci.org/mgrigajtis/easyzpl)
2
3
 
3
4
  Makes it easy to write ZPL & ZPL2.
4
5
 
@@ -18,7 +19,24 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ require 'rubygems'
23
+ require 'easyzpl'
24
+
25
+ # Create a simple label
26
+ label = Easyzpl::Label.new
27
+ label.home_position(30, 30)
28
+ label.draw_border(0, 0, 400, 300)
29
+ label.text_field('ZEBRA', 10, 10)
30
+ label.bar_code_39('ZEBRA', 10, 30)
31
+ puts label.to_s
32
+
33
+ # Create a stored template
34
+ label = Easyzpl::LabelTemplate.new('Template1')
35
+ label.home_position(30, 30)
36
+ label.draw_border(0, 0, 400, 300)
37
+ label.variable_text_field(10, 10)
38
+ label.variable_bar_code_39(10, 30)
39
+ puts label.to_s
22
40
 
23
41
  ## Contributing
24
42
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task default: :spec
8
+ task test: :spec
data/easyzpl.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
23
24
  end
@@ -0,0 +1,75 @@
1
+ # This module is a wrapper for writing confusing ZPL and ZPL2 code
2
+ module Easyzpl
3
+ # This is the label object
4
+ class Label
5
+ attr_accessor :label_data
6
+ attr_accessor :quantity
7
+
8
+ # Called when the new method is invoked
9
+ def initialize
10
+ # Create the array that will hold the data
11
+ self.label_data = []
12
+
13
+ # Set the default quantity to one
14
+ self.quantity = 1
15
+
16
+ # The start of the label
17
+ label_data.push('^XA')
18
+ end
19
+
20
+ # Set the number of labels to print
21
+ def change_quantity(q)
22
+ q = 1 unless numeric?(q)
23
+ self.quantity = q
24
+ end
25
+
26
+ # Set the home position of the label
27
+ # All other X and Y coordinates are
28
+ # relative to this
29
+ def home_position(x, y)
30
+ x = 0 unless numeric?(x)
31
+ y = 0 unless numeric?(y)
32
+ label_data.push('^LH' + x.to_s + ',' + y.to_s)
33
+ end
34
+
35
+ # Draws a square border on dot in width
36
+ def draw_border(x, y, length, width)
37
+ x = 0 unless numeric?(x)
38
+ y = 0 unless numeric?(y)
39
+ return unless numeric?(length) && numeric?(width)
40
+ label_data.push('^FO' + x.to_s + ',' + y.to_s + '^GB' + length.to_s +
41
+ ',' + width.to_s + ',1^FS')
42
+ end
43
+
44
+ # Prints text
45
+ def text_field(text, x, y, params = {})
46
+ x = 0 unless numeric?(x)
47
+ y = 0 unless numeric?(y)
48
+ options = { height: 10.to_s, width: 10.to_s }.merge(params)
49
+ label_data.push('^FO' + x.to_s + ',' + y.to_s + '^AFN,' +
50
+ options[:height] + ',' + options[:width] +
51
+ '^FD' + text + '^FS')
52
+ end
53
+
54
+ # Prints a bar code in barcode39 font
55
+ def bar_code_39(bar_code_string, x, y)
56
+ x = 0 unless numeric?(x)
57
+ y = 0 unless numeric?(y)
58
+ label_data.push('^FO' + x.to_s + ',' + y.to_s + '^B3N,Y,20,N,N^FD' +
59
+ bar_code_string + '^FS')
60
+ end
61
+
62
+ # Renders the ZPL code as a string
63
+ def to_s
64
+ return '' unless label_data.length > 0
65
+ label_data.map! { |l| "#{l}" }.join('') + '^PQ' + quantity.to_s + '^XZ'
66
+ end
67
+
68
+ protected
69
+
70
+ # Returns true if a variable is number, false if not
71
+ def numeric?(variable)
72
+ true if Integer(variable) rescue false
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'label'
2
+
3
+ # This module is a wrapper for writing confusing ZPL and ZPL2 code
4
+ module Easyzpl
5
+ # This is the label template object
6
+ # This gets uploaded and saved on the printer
7
+ class LabelTemplate < Easyzpl::Label
8
+ attr_accessor :variable_fields_count
9
+
10
+ # Called when the new method is invoked
11
+ def initialize(name)
12
+ return if name.nil?
13
+ return if name.strip.empty?
14
+
15
+ # Set the number of variable fields
16
+ self.variable_fields_count = 0
17
+
18
+ # Create the array that will hold the data
19
+ self.label_data = []
20
+
21
+ # Set the default quantity to one
22
+ self.quantity = 1
23
+
24
+ # The start of the label
25
+ label_data.push('^XA^DF' + name + '^FS')
26
+ end
27
+
28
+ # Sets a variable field that can be recalled
29
+ def variable_text_field(x, y)
30
+ x = 0 unless numeric?(x)
31
+ y = 0 unless numeric?(y)
32
+
33
+ # update the variable field count
34
+ self.variable_fields_count += 1
35
+
36
+ label_data.push('^FO' + x.to_s + ',' + y.to_s + '^FN' +
37
+ variable_fields_count.to_s + '^FS')
38
+ end
39
+
40
+ # Sets a variable bar code that can be recalled
41
+ def variable_bar_code_39(x, y)
42
+ x = 0 unless numeric?(x)
43
+ y = 0 unless numeric?(y)
44
+
45
+ # update the variable field count
46
+ self.variable_fields_count += 1
47
+
48
+ label_data.push('^FO' + x.to_s + ',' + y.to_s + '^B3N,Y,20,N,N^FN' +
49
+ variable_fields_count.to_s + '^FS')
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'label'
2
+
3
+ # This module is a wrapper for writing confusing ZPL and ZPL2 code
4
+ module Easyzpl
5
+ # This is the stored label object
6
+ class StoredLabel < Easyzpl::Label
7
+ attr_accessor :variable_fields_count
8
+
9
+ # Called when the new method is invoked
10
+ def initialize(name)
11
+ return if name.nil?
12
+ return if name.strip.empty?
13
+
14
+ # Set the number of variable fields
15
+ self.variable_fields_count = 0
16
+
17
+ # Create the array that will hold the data
18
+ self.label_data = []
19
+
20
+ # Set the default quantity to one
21
+ self.quantity = 1
22
+
23
+ # The start of the label
24
+ label_data.push('^XA^XF' + name + '^FS')
25
+ end
26
+
27
+ # Adds a variable that is to be applied to the saved template
28
+ def add_field(value)
29
+ return if value.nil?
30
+ return if value.strip.empty?
31
+
32
+ # Increment the variable field count
33
+ self.variable_fields_count += 1
34
+
35
+ # Add the field
36
+ label_data.push('^FN' + variable_fields_count.to_s + '^FD' + value + '^FS')
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,4 @@
1
+ # Section holds the version number of the Gem
1
2
  module Easyzpl
2
- VERSION = "0.0.1"
3
+ VERSION = '0.1.0'
3
4
  end
data/lib/easyzpl.rb CHANGED
@@ -1,68 +1,3 @@
1
1
  require 'easyzpl/version'
2
-
3
- # This module is a wrapper for writing confusing ZPL and ZPL2 code
4
- module Easyzpl
5
- # This is the label object
6
- class Label
7
- attr_accessor :label_data
8
- attr_accessor :quantity
9
-
10
- def initialize
11
- # Create the array that will hold the data
12
- self.label_data = []
13
-
14
- # Set the default quantity to one
15
- self.quantity = 1
16
-
17
- # The start of the label
18
- label_data.push('^XA')
19
- end
20
-
21
- # Set the number of labels to print
22
- def change_quantity(q)
23
- q = 1 unless numeric?(q)
24
- self.quantity = q
25
- end
26
-
27
- def home_position(x, y)
28
- x = 0 unless numeric?(x)
29
- y = 0 unless numeric?(y)
30
- label_data.push('^LH' + x.to_s + ',' + y.to_s)
31
- end
32
-
33
- def draw_border(x, y, length, width)
34
- x = 0 unless numeric?(x)
35
- y = 0 unless numeric?(y)
36
- return unless numeric?(length) && numeric?(width)
37
- label_data.push('^FO' + x.to_s + ',' + y.to_s + '^GB' + length.to_s +
38
- ',' + width.to_s + ',1^FS')
39
- end
40
-
41
- def text_field(text, x, y, params = {})
42
- x = 0 unless numeric?(x)
43
- y = 0 unless numeric?(y)
44
- options = { height: 10.to_s, width: 10.to_s }.merge(params)
45
- label_data.push('^FO' + x.to_s + ',' + y.to_s + '^AFN,' +
46
- options[:height] + ',' + options[:width] +
47
- '^FD' + text + '^FS')
48
- end
49
-
50
- def bar_code_39(bar_code_string, x, y)
51
- x = 0 unless numeric?(x)
52
- y = 0 unless numeric?(y)
53
- label_data.push('^FO' + x.to_s + ',' + y.to_s + '^B3N,Y,20,N,N^FD' +
54
- bar_code_string + '^FS')
55
- end
56
-
57
- def to_s
58
- return '' unless label_data.length > 0
59
- label_data.map! { |l| "#{l}" }.join('') + '^PQ' + quantity.to_s + '^XZ'
60
- end
61
-
62
- private
63
-
64
- def numeric?(variable)
65
- true if Integer(variable) rescue false
66
- end
67
- end
68
- end
2
+ require 'easyzpl/stored_label'
3
+ require 'easyzpl/label_template'
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Testing easyzpl Gem' do
4
+ context 'When creating an empty label' do
5
+ it 'should output a blank label' do
6
+ label = Easyzpl::Label.new
7
+ expect(label.to_s).to eq('^XA^PQ1^XZ')
8
+ end
9
+ end
10
+
11
+ context 'When creating a simple lable' do
12
+ it 'should output a label with the text "Zebra" and a barcode representation' do
13
+ label = Easyzpl::Label.new
14
+ label.home_position(30, 30)
15
+ label.draw_border(0, 0, 400, 300)
16
+ label.text_field('ZEBRA', 10, 10)
17
+ label.bar_code_39('ZEBRA', 10, 30)
18
+ expect(label.to_s).to eq('^XA^LH30,30^FO0,0^GB400,300,1^FS^FO10,10^AFN,10,10^FDZEBRA^FS^FO10,30^B3N,Y,20,N,N^FDZEBRA^FS^PQ1^XZ')
19
+ end
20
+ end
21
+
22
+ context 'When creating a stored template' do
23
+ it 'should output a label templage with one variable text field and one variable barcode' do
24
+ label = Easyzpl::LabelTemplate.new('Template1')
25
+ label.home_position(30, 30)
26
+ label.draw_border(0, 0, 400, 300)
27
+ label.variable_text_field(10, 10)
28
+ label.variable_bar_code_39(10, 30)
29
+ expect(label.to_s).to eq('^XA^DFTemplate1^FS^LH30,30^FO0,0^GB400,300,1^FS^FO10,10^FN1^FS^FO10,30^B3N,Y,20,N,N^FN2^FS^PQ1^XZ')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'easyzpl'
5
+
6
+ RSpec.configure do
7
+ # some (optional) config here
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyzpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Grigajtis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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'
41
55
  description: This Gem is a wrapper for the ZPL and ZPL 2 languages that are used to
42
56
  build labels for Zebra printers.
43
57
  email:
@@ -46,6 +60,8 @@ executables: []
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
63
+ - ".rspec"
64
+ - ".travis.yml"
49
65
  - Gemfile
50
66
  - LICENSE
51
67
  - LICENSE.txt
@@ -53,7 +69,12 @@ files:
53
69
  - Rakefile
54
70
  - easyzpl.gemspec
55
71
  - lib/easyzpl.rb
72
+ - lib/easyzpl/label.rb
73
+ - lib/easyzpl/label_template.rb
74
+ - lib/easyzpl/stored_label.rb
56
75
  - lib/easyzpl/version.rb
76
+ - spec/easyzpl_spec.rb
77
+ - spec/spec_helper.rb
57
78
  homepage: https://github.com/mgrigajtis/easyzpl
58
79
  licenses:
59
80
  - GPL
@@ -78,4 +99,6 @@ rubygems_version: 2.2.2
78
99
  signing_key:
79
100
  specification_version: 4
80
101
  summary: Makes it easy to write ZPL & ZPL2.
81
- test_files: []
102
+ test_files:
103
+ - spec/easyzpl_spec.rb
104
+ - spec/spec_helper.rb