Class: Zebra::Zpl::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/zebra/zpl/label.rb

Defined Under Namespace

Classes: InvalidPrintSpeedError, PrintSpeedNotInformedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Label



13
14
15
16
# File 'lib/zebra/zpl/label.rb', line 13

def initialize(options = {})
  options.each_pair { |key, value| self.__send__("#{key}=", value) if self.respond_to?("#{key}=") }
  @elements = []
end

Instance Attribute Details

#copiesObject



23
24
25
# File 'lib/zebra/zpl/label.rb', line 23

def copies
  @copies || 1
end

#elementsObject (readonly)

Returns the value of attribute elements.



10
11
12
# File 'lib/zebra/zpl/label.rb', line 10

def elements
  @elements
end

#label_shiftObject



27
28
29
# File 'lib/zebra/zpl/label.rb', line 27

def label_shift
  @label_shift || 10
end

#lengthObject

Returns the value of attribute length.



11
12
13
# File 'lib/zebra/zpl/label.rb', line 11

def length
  @length
end

Returns the value of attribute print_speed.



11
12
13
# File 'lib/zebra/zpl/label.rb', line 11

def print_speed
  @print_speed
end

#tempfileObject (readonly)

Returns the value of attribute tempfile.



10
11
12
# File 'lib/zebra/zpl/label.rb', line 10

def tempfile
  @tempfile
end

#widthObject

Returns the value of attribute width.



11
12
13
# File 'lib/zebra/zpl/label.rb', line 11

def width
  @width
end

Instance Method Details

#<<(element) ⇒ Object



31
32
33
34
# File 'lib/zebra/zpl/label.rb', line 31

def <<(element)
  element.width = self.width if element.respond_to?("width=") && element.width.nil?
  elements << element
end

#dump_contents(io = STDOUT) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/zebra/zpl/label.rb', line 36

def dump_contents(io = STDOUT)
  check_required_configurations
  # Start format
  io << "^XA"
  # ^LL<label height in dots>,<space between labels in dots>
  # io << "^LL#{length},#{gap}\n" if length && gap
  io << "^LL#{length}" if length
  # ^LH<label home - x,y coordinates of top left label>
  io << "^LH0,0"
  # ^LS<shift the label to the left(or right)>
  io << "^LS#{label_shift}"
  # ^PW<label width in dots>
  io << "^PW#{width}" if width
  # Print Rate(speed) (^PR command)
  io << "^PR#{print_speed}"
  # Density (D command) "Carried over from EPL, does this exist in ZPL ????"
  # io << "D#{print_density}\n" if print_density

  # TEST ZPL (comment everything else out)...
  # io << "^XA^WD*:*.FNT*^XZ"
  # TEST ZPL SEGMENT
  # io << "^WD*:*.FNT*"
  # TEST AND GET CONFIGS
  # io << "^HH"

  elements.each do |element|
    io << element.to_zpl
  end
  # Specify how many copies to print
  io << "^PQ#{copies}"
  # End format
  io << "^XZ"
end

#persistObject



70
71
72
73
74
75
76
# File 'lib/zebra/zpl/label.rb', line 70

def persist
  tempfile = Tempfile.new "zebra_label"
  dump_contents tempfile
  tempfile.close
  @tempfile = tempfile
  tempfile
end

#persisted?Boolean



78
79
80
# File 'lib/zebra/zpl/label.rb', line 78

def persisted?
  !!self.tempfile
end