Class: Zwischen::Finding::Finding
- Inherits:
-
Object
- Object
- Zwischen::Finding::Finding
- Defined in:
- lib/zwischen/finding/finding.rb
Constant Summary collapse
- SEVERITY_LEVELS =
%w[critical high medium low info].freeze
Instance Attribute Summary collapse
-
#code_snippet ⇒ Object
readonly
Returns the value of attribute code_snippet.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#rule_id ⇒ Object
readonly
Returns the value of attribute rule_id.
-
#scanner ⇒ Object
readonly
Returns the value of attribute scanner.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #critical? ⇒ Boolean
- #high? ⇒ Boolean
-
#initialize(type:, scanner:, severity:, file:, line: nil, message:, rule_id: nil, code_snippet: nil, raw_data: {}) ⇒ Finding
constructor
A new instance of Finding.
- #should_fail? ⇒ Boolean
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(type:, scanner:, severity:, file:, line: nil, message:, rule_id: nil, code_snippet: nil, raw_data: {}) ⇒ Finding
Returns a new instance of Finding.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/zwischen/finding/finding.rb', line 10 def initialize( type:, scanner:, severity:, file:, line: nil, message:, rule_id: nil, code_snippet: nil, raw_data: {} ) @type = type.to_s @scanner = scanner.to_s @severity = normalize_severity(severity) @file = file.to_s @line = line @message = .to_s @rule_id = rule_id.to_s if rule_id @code_snippet = code_snippet @raw_data = raw_data end |
Instance Attribute Details
#code_snippet ⇒ Object (readonly)
Returns the value of attribute code_snippet.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def code_snippet @code_snippet end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def line @line end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def @message end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def raw_data @raw_data end |
#rule_id ⇒ Object (readonly)
Returns the value of attribute rule_id.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def rule_id @rule_id end |
#scanner ⇒ Object (readonly)
Returns the value of attribute scanner.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def scanner @scanner end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def severity @severity end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/zwischen/finding/finding.rb', line 6 def type @type end |
Instance Method Details
#critical? ⇒ Boolean
51 52 53 |
# File 'lib/zwischen/finding/finding.rb', line 51 def critical? @severity == "critical" end |
#high? ⇒ Boolean
55 56 57 |
# File 'lib/zwischen/finding/finding.rb', line 55 def high? @severity == "high" end |
#should_fail? ⇒ Boolean
59 60 61 |
# File 'lib/zwischen/finding/finding.rb', line 59 def should_fail? critical? || high? end |
#to_h ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/zwischen/finding/finding.rb', line 32 def to_h { type: @type, scanner: @scanner, severity: @severity, file: @file, line: @line, message: @message, rule_id: @rule_id, code_snippet: @code_snippet, raw_data: @raw_data } end |
#to_json(*args) ⇒ Object
46 47 48 49 |
# File 'lib/zwischen/finding/finding.rb', line 46 def to_json(*args) require "json" unless defined?(JSON) to_h.to_json(*args) end |