Sha256: 537288e9ae4808132ae78e8ee044317adb905a6fef9d37546b5abd16420c0905

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

module Zebra
  class PrintJob
    # class UnknownPrinter < StandardError
    #   def initialize(printer)
    #     super("Could not find a printer named #{printer}")
    #   end
    # end

    attr_reader :printer

    def initialize(printer)
      #check_existent_printers printer

      @printer = printer
    end

    def print(label, ip)
      @remote_ip = ip
      tempfile = label.persist
      send_to_printer tempfile.path
    end

    private

    # def check_existent_printers(printer)
    #   existent_printers = Cups.show_destinations
    #   raise UnknownPrinter.new(printer) unless existent_printers.include?(printer)
    # end

    def send_to_printer(path)
      puts "Sending job to #{printer} printer on #{remote_ip}"
      # Try UNIX first
      `lp -h #{@remote_ip} -d #{@printer} -o raw #{path}`
    rescue # Must be Windows
      `lpr -S #{@remote_ip} -P #{@printer} -o raw #{path}`
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zebra-zpl-1.0.1 lib/zebra/print_job.rb