class Metascan::Batch

A batch of scanned files. Exposes similar methods to Scan, but for a group of files.

Attributes

scans[RW]

@scans is a hash like so: {

filename (string) => <Metascan::Scan>,
filename (string) => <Metascan::Scan>,
...

}

Public Class Methods

new(hydra) click to toggle source
# File lib/metascan/batch.rb, line 18
def initialize(hydra)
  @scans = {}
  @hydra = hydra
end

Public Instance Methods

add(scan) click to toggle source

Add a scan to my scans, man.

# File lib/metascan/batch.rb, line 24
def add(scan)
  unless scan.kind_of? Metascan::Scan
   raise TypeError, "Must pass a Scan object to Batch.add"
  end
  @scans = @scans.merge({ scan.filename => scan })
  @hydra.queue scan.request
end
clean?() click to toggle source

Return true iff all my scans are clean.

# File lib/metascan/batch.rb, line 33
def clean?
  @scans.map{ |id, s| s.clean? poll: true }.inject{ |s1, s2| s1 && s2 }
end
dirty() click to toggle source

Return a list of all the dirty scans in my batch.

# File lib/metascan/batch.rb, line 38
def dirty
  @scans.select{ |id, s| !(s.clean? poll: true) }.map{ |id, s| s }
end
retrieve_results() click to toggle source

Retrieve results for all the Scans in my batch. Uses the hydra for parallel processing. Call this AFTER calling run.

# File lib/metascan/batch.rb, line 49
def retrieve_results
  results_hydra = Typhoeus::Hydra.new
  @scans.each do |id, s|
    results_hydra.queue(s.retrieve_results)
  end
  results_hydra.run
end
run() click to toggle source
# File lib/metascan/batch.rb, line 42
def run
  @hydra.run
end