Class: SecureKeys::Validation::ScanResult
- Inherits:
-
Object
- Object
- SecureKeys::Validation::ScanResult
- Defined in:
- lib/validation/models/scan_result.rb
Overview
Aggregates all findings from a single scan run
Instance Attribute Summary collapse
-
#files_count ⇒ Object
readonly
Returns the value of attribute files_count.
-
#findings ⇒ Object
readonly
Returns the value of attribute findings.
Instance Method Summary collapse
-
#by_severity(severity:) ⇒ Array<Finding>
Returns findings filtered by a specific severity level.
-
#clean? ⇒ Boolean
Check if the scan produced no findings.
-
#initialize(findings:, files_count:) ⇒ ScanResult
constructor
Initialize a new scan result.
-
#to_h ⇒ Hash
Returns a hash representation of the scan result.
Constructor Details
#initialize(findings:, files_count:) ⇒ ScanResult
Initialize a new scan result
12 13 14 15 |
# File 'lib/validation/models/scan_result.rb', line 12 def initialize(findings:, files_count:) @findings = findings @files_count = files_count end |
Instance Attribute Details
#files_count ⇒ Object (readonly)
Returns the value of attribute files_count.
7 8 9 |
# File 'lib/validation/models/scan_result.rb', line 7 def files_count @files_count end |
#findings ⇒ Object (readonly)
Returns the value of attribute findings.
7 8 9 |
# File 'lib/validation/models/scan_result.rb', line 7 def findings @findings end |
Instance Method Details
#by_severity(severity:) ⇒ Array<Finding>
Returns findings filtered by a specific severity level
26 27 28 |
# File 'lib/validation/models/scan_result.rb', line 26 def by_severity(severity:) findings.select { |finding| finding.severity == severity } end |
#clean? ⇒ Boolean
Check if the scan produced no findings
19 20 21 |
# File 'lib/validation/models/scan_result.rb', line 19 def clean? findings.empty? end |
#to_h ⇒ Hash
Returns a hash representation of the scan result
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/validation/models/scan_result.rb', line 32 def to_h { files_scanned: files_count, total_findings: findings.length, by_severity: { critical: by_severity(severity: :critical).length, high: by_severity(severity: :high).length, medium: by_severity(severity: :medium).length, low: by_severity(severity: :low).length, }, findings: findings.map(&:to_h), } end |