Class: Escpos::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/escpos/printer.rb

Instance Method Summary collapse

Constructor Details

#initializePrinter

Returns a new instance of Printer.



6
7
8
9
10
# File 'lib/escpos/printer.rb', line 6

def initialize
  # ensure only supported sequences are generated
  @data = "".force_encoding("ASCII-8BIT")
  @data << Escpos.sequence(HW_INIT)
end

Instance Method Details

#cut!Object



22
23
24
# File 'lib/escpos/printer.rb', line 22

def cut!
  @data << Escpos.sequence(PAPER_FULL_CUT)
end

#partial_cut!Object



18
19
20
# File 'lib/escpos/printer.rb', line 18

def partial_cut!
  @data << Escpos.sequence(PAPER_PARTIAL_CUT)
end

#save(path) ⇒ Object



26
27
28
29
30
# File 'lib/escpos/printer.rb', line 26

def save(path)
  File.open(path, "wb") do |f|
    f.print to_escpos
  end
end

#to_base64Object



36
37
38
# File 'lib/escpos/printer.rb', line 36

def to_base64
  Base64.strict_encode64 @data
end

#to_escposObject



32
33
34
# File 'lib/escpos/printer.rb', line 32

def to_escpos
  @data
end

#write(data) ⇒ Object Also known as: <<



12
13
14
15
# File 'lib/escpos/printer.rb', line 12

def write(data)
  escpos_data = data.respond_to?(:to_escpos) ? data.to_escpos : data
  @data << escpos_data.force_encoding("ASCII-8BIT")
end