Class: Zebra::Epl::Label

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

Defined Under Namespace

Classes: InvalidPrintDensityError, InvalidPrintSpeedError, PrintSpeedNotInformedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Label

Returns a new instance of Label.



13
14
15
16
# File 'lib/zebra/epl/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

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#gapObject

Returns the value of attribute gap.



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

def gap
  @gap
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

Returns the value of attribute print_density.



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

def print_density
  @print_density
end

Returns the value of attribute print_speed.



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

def print_speed
  @print_speed
end

#tempfileObject (readonly)

Returns the value of attribute tempfile.



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

def tempfile
  @tempfile
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#<<(element) ⇒ Object



33
34
35
# File 'lib/zebra/epl/label.rb', line 33

def <<(element)
  elements << element
end

#dump_contents(io = STDOUT) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/zebra/epl/label.rb', line 37

def dump_contents(io = STDOUT)
  check_required_configurations
  # Start options
  io << "O\n"
  # Q<label height in dots>,<space between labels in dots>
  io << "Q#{length},#{gap}\n" if length && gap
  # q<label width in dots>
  io << "q#{width}\n" if width
  # Print Speed (S command)
  io << "S#{print_speed}\n"
  # Density (D command)
  io << "D#{print_density}\n" if print_density
  # ZT = Printing from top of image buffer.

  io << "\n"
  # Start new label
  io << "N\n"

  elements.each do |element|
    io << element.to_epl << "\n"
  end

  io << "P0\n"
end

#length_and_gap=(length_and_gap) ⇒ Object



18
19
20
21
# File 'lib/zebra/epl/label.rb', line 18

def length_and_gap=(length_and_gap)
  self.length = length_and_gap[0]
  self.gap    = length_and_gap[1]
end

#persistObject



62
63
64
65
66
67
68
# File 'lib/zebra/epl/label.rb', line 62

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

#persisted?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/zebra/epl/label.rb', line 70

def persisted?
  !!self.tempfile
end