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.
-
#environmental ⇒ Object
readonly
Metric of a CVSS vector.
-
#temporal ⇒ Object
readonly
Metric of a CVSS vector.
Instance Method Summary collapse
-
#initialize(vector) ⇒ Cvss
constructor
Creates a new CVSS vector by a
vector
. -
#overall_score ⇒ Object
Returns the Overall Score of the CVSS vector.
-
#severity ⇒ Object
Returns the severity of the CVSS vector.
-
#valid? ⇒ Boolean
Returns if CVSS vector is valid.
-
#vector ⇒ Object
Returns the vector itself.
Constructor Details
#initialize(vector) ⇒ Cvss
Creates a new CVSS vector by a vector
.
Raises an exception if it is called on Cvss class.
24 25 26 27 28 29 30 31 |
# File 'lib/cvss_suite/cvss.rb', line 24 def initialize(vector) raise CvssSuite::Errors::InvalidParentClass, 'Do not instantiate this class!' if instance_of? Cvss @vector = vector @properties = [] extract_metrics init_metrics end |
Instance Attribute Details
#base ⇒ Object (readonly)
Metric of a CVSS vector.
18 19 20 |
# File 'lib/cvss_suite/cvss.rb', line 18 def base @base end |
#environmental ⇒ Object (readonly)
Metric of a CVSS vector.
18 19 20 |
# File 'lib/cvss_suite/cvss.rb', line 18 def environmental @environmental end |
#temporal ⇒ Object (readonly)
Metric of a CVSS vector.
18 19 20 |
# File 'lib/cvss_suite/cvss.rb', line 18 def temporal @temporal end |
Instance Method Details
#overall_score ⇒ Object
Returns the Overall Score of the CVSS vector.
71 72 73 74 75 76 77 |
# File 'lib/cvss_suite/cvss.rb', line 71 def overall_score check_validity return temporal_score if @temporal.valid? && !@environmental.valid? return environmental_score if @environmental.valid? base_score end |
#severity ⇒ Object
Returns the severity of the CVSS vector.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cvss_suite/cvss.rb', line 49 def severity check_validity score = overall_score 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 |
#valid? ⇒ Boolean
Returns if CVSS vector is valid.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cvss_suite/cvss.rb', line 35 def valid? if @amount_of_properties >= required_amount_of_properties base = @base.valid? temporal = @base.valid? && @temporal.valid? environmental = @base.valid? && @environmental.valid? full = @base.valid? && @temporal.valid? && @environmental.valid? base || temporal || environmental || full else false end end |
#vector ⇒ Object
Returns the vector itself.
81 82 83 |
# File 'lib/cvss_suite/cvss.rb', line 81 def vector @vector.to_s end |