51 lines
954 B
Ruby
51 lines
954 B
Ruby
require 'net/http'
|
|
require 'cups'
|
|
|
|
class Printer::PrinterWorker
|
|
attr_accessor :print_settings
|
|
|
|
def initialize(print_settings)
|
|
self.print_settings = print_settings
|
|
end
|
|
|
|
def printer_destination()
|
|
if self.print_settings
|
|
self.print_settings.printer_name
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
def print_copies()
|
|
if self.print_settings
|
|
self.print_settings.print_copies.to_i
|
|
else
|
|
return 1
|
|
end
|
|
end
|
|
|
|
def printers()
|
|
Cups.show_destinations
|
|
end
|
|
|
|
def default_printer()
|
|
Cups.default_printer
|
|
end
|
|
|
|
def print(file_path,printer_destination = nil )
|
|
|
|
if printer_destination.nil?
|
|
printer_destination = self.printer_destination
|
|
end
|
|
|
|
copy = self.print_copies
|
|
#Print only when printer information is not null
|
|
if !self.printer_destination.nil?
|
|
(1..copy).each do
|
|
page = Cups::PrintJob.new(file_path, printer_destination)
|
|
page.print
|
|
end
|
|
end
|
|
end
|
|
end
|