Class: Easyzpl::LabelTemplate

Inherits:
Label
  • Object
show all
Defined in:
lib/easyzpl/label_template.rb

Overview

This is the label template object This gets uploaded and saved on the printer

Instance Attribute Summary collapse

Attributes inherited from Label

#label_data, #label_height, #label_width, #pdf, #quantity

Instance Method Summary collapse

Methods inherited from Label

#bar_code_39, #change_quantity, #draw_border, #home_position, #text_field, #to_pdf, #to_s

Constructor Details

#initialize(name, params = {}) ⇒ LabelTemplate

Called when the new method is invoked



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/easyzpl/label_template.rb', line 15

def initialize(name, params = {})
  return if name.nil?
  return if name.strip.empty?

  # Set the number of variable fields
  self.variable_fields_count = 0

  # Create the array that will hold the data
  self.label_data = []

  # Set the default quantity to one
  self.quantity = 1

  # The start of the label
  label_data.push('^XA^DF' + name + '^FS')

  init_prawn(params)
end

Instance Attribute Details

#variable_fields_countObject

Returns the value of attribute variable_fields_count.



12
13
14
# File 'lib/easyzpl/label_template.rb', line 12

def variable_fields_count
  @variable_fields_count
end

Instance Method Details

#variable_bar_code_39(x, y, params = {}) ⇒ Object

Sets a variable bar code that can be recalled



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/easyzpl/label_template.rb', line 54

def variable_bar_code_39(x, y, params = {})
  x = 0 unless numeric?(x)
  y = 0 unless numeric?(y)

  # update the variable field count
  self.variable_fields_count += 1

  label_data.push('^FO' + x.to_s + ',' + y.to_s + '^B3N,Y,20,N,N^FN' +
                  variable_fields_count.to_s + '^FS')

  return unless label_height && label_width
  options = { height: 20 }.merge(params)
  draw_bar_code_39('VARIABLEFIELD' + variable_fields_count.to_s,
                   x, y, options[:height])
end

#variable_text_field(x, y, params = {}) ⇒ Object

Sets a variable field that can be recalled



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/easyzpl/label_template.rb', line 35

def variable_text_field(x, y, params = {})
  x = 0 unless numeric?(x)
  y = 0 unless numeric?(y)
  options = { height: 10, width: 10 }.merge(params)

  # update the variable field count
  self.variable_fields_count += 1

  label_data.push('^FO' + x.to_s + ',' + y.to_s + '^AFN,' +
                  options[:height].to_s + ',' + options[:width].to_s +
                   '^FN' + variable_fields_count.to_s + '^FS')

  return unless label_height > 0 && label_width > 0
  pdf.text_box '{Variable Field ' + variable_fields_count.to_s + '}',
               at: [x, label_width - y - Integer(options[:height] / 10)],
               size: options[:height] if label_height && label_width
end