class

CVSS::Vector

Inherits Comparable < Reference < Object

Common interface for every CVSS vector implementation.

Each version (V2, V3, V4) implements its own subclass of this abstract base. The shared API lets callers treat any parsed vector uniformly:

vec = CVSS.parse(input)
vec.base_score # => Float64
vec.severity   # => CVSS::Severity
vec.version    # => "3.1"
vec.to_s       # => canonical vector string

Vectors are Comparable by base_score — sort/compare across versions by severity:

vulns = inputs.map { |s| CVSS.parse(s) }
vulns.sort.last # most severe
vulns.min       # least severe

Equality is structural and class-aware: two vectors are == only when they are the same concrete class with identical metric values. A v3 and v4 vector that happen to share a base_score are not ==.

Instance methods

<=>(other : Vector) : Int32 | Nil

Order vectors by their base score. Subclasses do not need to override. Returns nil only if a score is NaN, which never happens for valid CVSS inputs — included for Float64#<=> compatibility.

Source
==(other : Vector) : Bool

Default cross-class equality: vectors of different concrete classes are never ==. Same-class subclasses override with field-level equality. This also overrides the == that Comparable would otherwise derive from <=> (we don't want score-equal vectors to compare equal).

Source
base_score
Source
inspect(io : IO) : Nil

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Source
severity
Source
to_json(json : JSON::Builder) : Nil
Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
to_s

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.

Source
version
Source