Class: Easyzpl::Label
- Inherits:
-
Object
- Object
- Easyzpl::Label
- Defined in:
- lib/easyzpl/label.rb
Overview
This is the label object
Direct Known Subclasses
Instance Attribute Summary collapse
-
#label_data ⇒ Object
Returns the value of attribute label_data.
-
#label_height ⇒ Object
Returns the value of attribute label_height.
-
#label_width ⇒ Object
Returns the value of attribute label_width.
-
#pdf ⇒ Object
Returns the value of attribute pdf.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
Instance Method Summary collapse
-
#bar_code_39(bar_code_string, x, y, params = {}) ⇒ Object
Prints a bar code in barcode39 font.
-
#change_quantity(q) ⇒ Object
Set the number of labels to print.
-
#draw_border(x, y, height, width) ⇒ Object
Draws a square border on dot in width.
-
#home_position(x, y) ⇒ Object
Set the home position of the label All other X and Y coordinates are relative to this.
-
#initialize(params = {}) ⇒ Label
constructor
Called when the new method is invoked.
-
#text_field(text, x, y, params = {}) ⇒ Object
Prints text.
- #to_pdf(filename) ⇒ Object
-
#to_s ⇒ Object
Renders the ZPL code as a string.
Constructor Details
#initialize(params = {}) ⇒ Label
Called when the new method is invoked
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/easyzpl/label.rb', line 17 def initialize(params = {}) # Create the array that will hold the data self.label_data = [] # Set the default quantity to one self.quantity = 1 # The start of the zpl label label_data.push('^XA') # Initialize Prawn init_prawn(params) end |
Instance Attribute Details
#label_data ⇒ Object
Returns the value of attribute label_data.
10 11 12 |
# File 'lib/easyzpl/label.rb', line 10 def label_data @label_data end |
#label_height ⇒ Object
Returns the value of attribute label_height.
14 15 16 |
# File 'lib/easyzpl/label.rb', line 14 def label_height @label_height end |
#label_width ⇒ Object
Returns the value of attribute label_width.
13 14 15 |
# File 'lib/easyzpl/label.rb', line 13 def label_width @label_width end |
#pdf ⇒ Object
Returns the value of attribute pdf.
12 13 14 |
# File 'lib/easyzpl/label.rb', line 12 def pdf @pdf end |
#quantity ⇒ Object
Returns the value of attribute quantity.
11 12 13 |
# File 'lib/easyzpl/label.rb', line 11 def quantity @quantity end |
Instance Method Details
#bar_code_39(bar_code_string, x, y, params = {}) ⇒ Object
Prints a bar code in barcode39 font
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/easyzpl/label.rb', line 74 def (, x, y, params = {}) x = 0 unless numeric?(x) y = 0 unless numeric?(y) label_data.push('^FO' + x.to_s + ',' + y.to_s + '^B3N,Y,20,N,N^FD' + + '^FS') return unless label_height && label_width = { height: 20 }.merge(params) (, x, y, [:height]) end |
#change_quantity(q) ⇒ Object
Set the number of labels to print
31 32 33 34 |
# File 'lib/easyzpl/label.rb', line 31 def change_quantity(q) q = 1 unless numeric?(q) self.quantity = q end |
#draw_border(x, y, height, width) ⇒ Object
Draws a square border on dot in width
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/easyzpl/label.rb', line 46 def draw_border(x, y, height, width) return unless numeric?(height) && numeric?(width) x = 0 unless numeric?(x) y = 0 unless numeric?(y) label_data.push('^FO' + x.to_s + ',' + y.to_s + '^GB' + height.to_s + ',' + width.to_s + ',1^FS') draw_rectangle(x, y, height, width) end |
#home_position(x, y) ⇒ Object
Set the home position of the label All other X and Y coordinates are relative to this
39 40 41 42 43 |
# File 'lib/easyzpl/label.rb', line 39 def home_position(x, y) x = 0 unless numeric?(x) y = 0 unless numeric?(y) label_data.push('^LH' + x.to_s + ',' + y.to_s) end |
#text_field(text, x, y, params = {}) ⇒ Object
Prints text
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/easyzpl/label.rb', line 58 def text_field(text, x, y, params = {}) x = 0 unless numeric?(x) y = 0 unless numeric?(y) = { height: 10, width: 10 }.merge(params) label_data.push('^FO' + x.to_s + ',' + y.to_s + '^AFN,' + [:height].to_s + ',' + [:width].to_s + '^FD' + text + '^FS') return unless label_height > 0 && label_width > 0 pdf.text_box text, at: [x, label_width - y - Integer([:height] / 10)], size: [:height] if label_height && label_width end |
#to_pdf(filename) ⇒ Object
91 92 93 94 |
# File 'lib/easyzpl/label.rb', line 91 def to_pdf(filename) return unless label_height && label_width pdf.render_file(filename) end |
#to_s ⇒ Object
Renders the ZPL code as a string
86 87 88 89 |
# File 'lib/easyzpl/label.rb', line 86 def to_s return '' unless label_data.length > 0 label_data.map! { |l| "#{l}" }.join('') + '^PQ' + quantity.to_s + '^XZ' end |