class Escpos::Printer

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

<<(data)
Alias for: write
cut!() click to toggle source
# File lib/escpos/printer.rb, line 22
def cut!
  @data << Escpos.sequence(PAPER_FULL_CUT)
end
partial_cut!() click to toggle source
# File lib/escpos/printer.rb, line 18
def partial_cut!
  @data << Escpos.sequence(PAPER_PARTIAL_CUT)
end
save(path) click to toggle source
# File lib/escpos/printer.rb, line 26
def save(path)
  File.open(path, "wb") do |f|
    f.print to_escpos
  end
end
to_base64() click to toggle source
# File lib/escpos/printer.rb, line 36
def to_base64
  Base64.strict_encode64 @data
end
to_escpos() click to toggle source
# File lib/escpos/printer.rb, line 32
def to_escpos
  @data
end
write(data) click to toggle source
# 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
Also aliased as: <<