Class: Apolo::Domains::Cups

Inherits:
Object
  • Object
show all
Defined in:
lib/apolo/domains/cups.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(printer_name) ⇒ Cups

Returns a new instance of Cups.



7
8
9
10
11
12
13
14
15
16
# File 'lib/apolo/domains/cups.rb', line 7

def initialize(printer_name)
  if printer_name.nil?
    printer = CupsPrinter.new(printers.first)
    @printer_name = printer.name
  else
    @printer_name = printer_name
  end

  get_data
end

Instance Attribute Details

#jobObject

Returns the value of attribute job.



6
7
8
# File 'lib/apolo/domains/cups.rb', line 6

def job
  @job
end

#jobs_countObject

Returns the value of attribute jobs_count.



6
7
8
# File 'lib/apolo/domains/cups.rb', line 6

def jobs_count
  @jobs_count
end

#minutesObject

Returns the value of attribute minutes.



6
7
8
# File 'lib/apolo/domains/cups.rb', line 6

def minutes
  @minutes
end

Instance Method Details

#get_dataObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/apolo/domains/cups.rb', line 22

def get_data
  pointer = FFI::MemoryPointer.new :pointer
  @jobs_count = CupsFFI::cupsGetJobs(pointer, @printer_name, 0, CupsFFI::CUPS_WHICHJOBS_ACTIVE)
  @job = CupsFFI::CupsJobS.new(pointer.get_pointer(0))

  if @jobs_count > 0
    @minutes = (Time.now - Time.at(@job[:creation_time])).to_i / 60
  else
    @minutes = 0
  end
end

#printersObject



18
19
20
# File 'lib/apolo/domains/cups.rb', line 18

def printers
  CupsPrinter.get_all_printer_names
end