class CVESchema::CVE::ID

Represents a CVE ID (ex: `CVE-2021-1234`).

Attributes

number[R]

The CVE number.

@return [String]

year[R]

The year the CVE ID was assigned.

@return [String]

Public Class Methods

new(year,number) click to toggle source

Initializes the CVE ID.

@param [String] year

The year the CVE ID was assigned.

@param [String] number

The CVE number.
# File lib/cve_schema/cve/id.rb, line 27
def initialize(year,number)
  @year   = year
  @number = number
end
parse(id) click to toggle source

Parses the CVE ID.

@param [String] id

The CVE ID string.

@raise [ArgumentError]

The given ID was not a valid CVE.
# File lib/cve_schema/cve/id.rb, line 41
def self.parse(id)
  cve, year, number = id.split('-',3)

  unless cve == 'CVE'
    raise(ArgumentError,"invalid CVE #{id.inspect}")
  end

  new(year,number)
end

Public Instance Methods

==(other) click to toggle source

Compares the ID with another ID.

@param [ID] other

The other ID.

@return [Boolean]

Identicates whether the IDs match.
# File lib/cve_schema/cve/id.rb, line 60
def ==(other)
  self.class == other.class && (
    @year   == other.year && 
    @number == other.number
  )
end
to_s() click to toggle source

Converts the CVE ID back into a String.

@return [String]

The full CVE ID (ex: `CVE-2021-1234`).
# File lib/cve_schema/cve/id.rb, line 73
def to_s
  "CVE-#{@year}-#{@number}"
end