Class: Cups::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-cups/job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, title, printer) ⇒ Job

Returns a new instance of Job.



7
8
9
10
11
# File 'lib/ffi-cups/job.rb', line 7

def initialize(id, title, printer)
  @id = id
  @title = title
  @printer = printer
end

Instance Attribute Details

#completed_timeObject

Returns the value of attribute completed_time.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def completed_time
  @completed_time
end

#creation_timeObject

Returns the value of attribute creation_time.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def creation_time
  @creation_time
end

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def format
  @format
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def id
  @id
end

#printerObject

Returns the value of attribute printer.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def printer
  @printer
end

#processing_timeObject

Returns the value of attribute processing_time.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def processing_time
  @processing_time
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def size
  @size
end

#stateObject

Returns the value of attribute state.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def state
  @state
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/ffi-cups/job.rb', line 3

def title
  @title
end

Class Method Details

.get_job(id, name = nil, filter = -1,, connection = nil) ⇒ Job

Get job from id

Parameters:

  • id (Integer)
  • name (String) (defaults to: nil)
  • filter (Integer) (defaults to: -1,)

    see Constants

  • connection (Cups::Connection) (defaults to: nil)

Returns:

  • (Job)

    job object



41
42
43
44
45
46
# File 'lib/ffi-cups/job.rb', line 41

def self.get_job(id, name=nil, filter=-1, connection=nil)
  jobs = get_jobs(name, filter, connection)
  jobs.each do |j|
    return j if j.id == id
  end
end

.get_jobs(name = nil, filter = -1,, connection = nil) ⇒ Array

Get jobs by filter or destination name

Parameters:

  • name (String) (defaults to: nil)
  • filter (Integer) (defaults to: -1,)

    see Constants

  • connection (Cups::Connection) (defaults to: nil)

Returns:

  • (Array)

    jobs



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ffi-cups/job.rb', line 18

def self.get_jobs(name=nil, filter=-1, connection=nil)
  p_jobs = FFI::MemoryPointer.new :pointer
  cups_jobs = cupsGetJobs2(p_jobs, name, filter, connection)
  jobs = []
  cups_jobs.each do |j|
    job = Cups::Job.new(j[:id].dup, j[:title].dup, j[:dest].dup)
    job.format = j[:format]
    job.state = j[:state]
    job.size = j[:size]
    job.completed_time = Time.at(j[:completed_time])
    job.creation_time = Time.at(j[:creation_time])
    job.processing_time = Time.at(j[:processing_time])
    jobs.push(job)
  end
  return jobs
end