Class: Metascan::Batch
- Inherits:
-
Object
- Object
- Metascan::Batch
- Defined in:
- lib/metascan/batch.rb
Overview
A batch of scanned files. Exposes similar methods to Scan, but for a group of files.
Instance Attribute Summary collapse
-
#scans ⇒ Object
{ filename (string) => <Metascan::Scan>, filename (string) => <Metascan::Scan>, … }.
Instance Method Summary collapse
-
#add(scan) ⇒ Object
Add a scan to my scans, man.
-
#clean? ⇒ Boolean
Return true iff all my scans are clean.
-
#dirty ⇒ Object
Return a list of all the dirty scans in my batch.
-
#initialize(hydra) ⇒ Batch
constructor
A new instance of Batch.
-
#retrieve_results ⇒ Object
Retrieve results for all the Scans in my batch.
- #run ⇒ Object
Constructor Details
#initialize(hydra) ⇒ Batch
Returns a new instance of Batch.
18 19 20 21 |
# File 'lib/metascan/batch.rb', line 18 def initialize(hydra) @scans = {} @hydra = hydra end |
Instance Attribute Details
#scans ⇒ Object
filename (string) => <Metascan::Scan>,
filename (string) => <Metascan::Scan>,
...
16 17 18 |
# File 'lib/metascan/batch.rb', line 16 def scans @scans end |
Instance Method Details
#add(scan) ⇒ Object
Add a scan to my scans, man.
24 25 26 27 28 29 30 |
# 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? ⇒ Boolean
Return true iff all my scans are clean.
33 34 35 |
# File 'lib/metascan/batch.rb', line 33 def clean? @scans.map{ |id, s| s.clean? poll: true }.inject{ |s1, s2| s1 && s2 } end |
#dirty ⇒ Object
Return a list of all the dirty scans in my batch.
38 39 40 |
# File 'lib/metascan/batch.rb', line 38 def dirty @scans.select{ |id, s| !(s.clean? poll: true) }.map{ |id, s| s } end |
#retrieve_results ⇒ Object
Retrieve results for all the Scans in my batch. Uses the hydra for parallel processing. Call this AFTER calling #run.
49 50 51 52 53 54 55 |
# 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 ⇒ Object
42 43 44 |
# File 'lib/metascan/batch.rb', line 42 def run @hydra.run end |