Class: CvssSuite::Cvss
- Inherits:
-
Object
- Object
- CvssSuite::Cvss
- Defined in:
- lib/cvss_suite/cvss.rb
Overview
This class represents any CVSS vector. Do not instantiate this class!
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Metric of a CVSS vector.
Instance Method Summary collapse
-
#initialize(vector, original = vector) ⇒ Cvss
constructor
Creates a new CVSS vector by a
vector. -
#severity ⇒ Object
Returns the severity of the CVSS vector.
-
#vector ⇒ Object
Returns the vector itself.
Constructor Details
#initialize(vector, original = vector) ⇒ Cvss
Creates a new CVSS vector by a vector. CvssSuite.new also passes the
original string it was handed, because vector reaches here with the
CVSS:x.x/ prefix or the CVSS 2 parentheses already stripped, and an error
has to name the vector the caller actually wrote.
Raises an exception if it is called on Cvss class.
23 24 25 26 27 28 29 30 31 |
# File 'lib/cvss_suite/cvss.rb', line 23 def initialize(vector, original = vector) raise CvssSuite::Errors::InvalidParentClass, 'Do not instantiate this class!' if instance_of? Cvss @vector = vector @original = original @properties = [] extract_metrics init_metrics end |
Instance Attribute Details
#base ⇒ Object (readonly)
Metric of a CVSS vector.
14 15 16 |
# File 'lib/cvss_suite/cvss.rb', line 14 def base @base end |
Instance Method Details
#severity ⇒ Object
Returns the severity of the CVSS vector.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cvss_suite/cvss.rb', line 35 def severity check_validity score = overall_score # The explicit `<= 0.0` branch and the defensive `else` both yield 'None' by # design (zero score vs. out-of-range guard); kept distinct for readability. # rubocop:disable-next Lint/DuplicateBranch if score <= 0.0 'None' elsif (0.1..3.9).cover? score 'Low' elsif (4.0..6.9).cover? score 'Medium' elsif (7.0..8.9).cover? score 'High' elsif (9.0..10.0).cover? score 'Critical' else 'None' end end |
#vector ⇒ Object
Returns the vector itself.
60 61 62 |
# File 'lib/cvss_suite/cvss.rb', line 60 def vector @vector.to_s end |