Class: Languages::Zpl2

Inherits:
Object
  • Object
show all
Defined in:
lib/languages/zpl2.rb,
lib/languages/zpl2/font.rb,
lib/languages/zpl2/text.rb,
lib/languages/zpl2/barcode.rb,
lib/languages/zpl2/document.rb,
lib/languages/zpl2/position.rb

Defined Under Namespace

Classes: Barcode1D, Barcode2D, BarcodeFactory, Document, Font, Position, Text

Instance Method Summary collapse

Constructor Details

#initializeZpl2

Returns a new instance of Zpl2.



9
10
11
12
13
14
# File 'lib/languages/zpl2.rb', line 9

def initialize
  @document = Zpl2::Document.new
  @font = Zpl2::Font.new
  @position = Zpl2::Position[0,0]
  @document << @position
end

Instance Method Details

#barcode(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/languages/zpl2.rb', line 46

def barcode(*args)
  opts = args.extract_options!
  code,text = args.pop 2

  opts = opts.merge({:font => @font,:text => text})

  if opts.include? :at
    @document << (@position + Zpl2::Position.from_array(opts[:at]))
  end

  @document << Zpl2::BarcodeFactory.create_barcode(code, opts)
end

#documentObject



72
73
74
# File 'lib/languages/zpl2.rb', line 72

def document
  @document.render
end

#font(opts = {}, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/languages/zpl2.rb', line 35

def font(opts={},&block)
  if block_given?
    @document << Zpl2::Font.new(opts)
    self.instance_eval &block
    @document << @font
  else
    @font = Zpl2::Font.new(opts)
    @document << @font
  end
end

#position(x, y, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/languages/zpl2.rb', line 59

def position(x,y,&block)
  if block_given?
    save = @position
    @position = Zpl2::Position[x,y]
    @document << @position
    self.instance_eval(&block)
    @position = save
  else
    @position = Zpl2::Position[x,y]
  end
  @document << @position
end

#rotate(amount, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/languages/zpl2.rb', line 24

def rotate(amount, &block)
  if block_given?
    @document << Zpl2::Font.new(:rotation => amount)
    self.instance_eval &block
    @document << @font
  else
    @font.font_rotation amount
    @document << @font
  end
end

#text(text, opts = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/languages/zpl2.rb', line 16

def text(text,opts={})
  if opts.include? :at
    @document << (@position + Zpl2::Position.from_array(opts[:at]))
  end
  @document << Zpl2::Text.new(text)
  @document << @position if opts.include?(:at)
end