Class: Nessana::Dump
- Inherits:
-
Hash
- Object
- Hash
- Nessana::Dump
- Defined in:
- lib/nessana/dump.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
Class Method Summary collapse
Instance Method Summary collapse
- #-(other) ⇒ Object
- #detection_pairs ⇒ Object
-
#initialize(vulnerabilities = {}, filters = []) ⇒ Dump
constructor
A new instance of Dump.
Constructor Details
#initialize(vulnerabilities = {}, filters = []) ⇒ Dump
Returns a new instance of Dump.
19 20 21 22 23 24 25 26 27 |
# File 'lib/nessana/dump.rb', line 19 def initialize(vulnerabilities = {}, filters = []) @filters = filters filtered_data = vulnerabilities.select do |_, vulnerability| !vulnerability.matches?(@filters) end merge!(filtered_data) end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
11 12 13 |
# File 'lib/nessana/dump.rb', line 11 def filters @filters end |
Class Method Details
.read(file, filters = []) ⇒ Object
13 14 15 16 17 |
# File 'lib/nessana/dump.rb', line 13 def self.read(file, filters = []) data = read_csv(file) self.new(data, filters) end |
Instance Method Details
#-(other) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nessana/dump.rb', line 29 def -(other) other_plugin_ids = other.keys self_plugin_ids = keys other_detections = other.detection_pairs self_detections = detection_pairs detections = Set.new([other_detections, self_detections]).flatten detections.each do |detection_entry| in_self = self_detections.include? detection_entry in_other = other_detections.include? detection_entry detection = detection_entry.values.first if in_self && in_other detection.status = :present elsif !in_self && in_other detection.status = :removed elsif in_self && !in_other detection.status = :added else detection.status = true end end added_plugin_ids = self_plugin_ids - other_plugin_ids deleted_plugin_ids = other_plugin_ids - self_plugin_ids all_plugin_ids = other_plugin_ids + added_plugin_ids all_vulnerabilities = all_plugin_ids.map do |plugin_id| vulnerability = nil if !self[plugin_id] vulnerability = other[plugin_id].clone else vulnerability = self[plugin_id].clone end plugin_detections = detections.select do |detection_entry| detection_entry.keys.first == vulnerability.plugin_id end.map do |detection_entry| detection_entry.values.first end vulnerability.detections = plugin_detections.map do |detection| detection.dup end vulnerability end all_vulnerabilities end |
#detection_pairs ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/nessana/dump.rb', line 84 def detection_pairs pairs = map do |plugin_id, vulnerability| vulnerability.detections.map do |detection| { plugin_id => detection } end end Set.new(pairs.flatten) end |