Sha256: 1643ec019f7b3b62c81471523f7737afc94a2b371965bbc2794f6b552989d8e9

Contents?: true

Size: 789 Bytes

Versions: 3

Compression:

Stored size: 789 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)
      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)
      if RUBY_PLATFORM =~ /darwin/
        `lpr -P #{@printer} -o raw #{path}`
      else
        `lp -d #{@printer} -o raw #{path}`
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zebra-epl-0.0.8 lib/zebra/print_job.rb
zebra-epl-0.0.7 lib/zebra/print_job.rb
zebra-epl-0.0.6 lib/zebra/print_job.rb