Class: CVESchema::CVE::ID
- Inherits:
-
Object
- Object
- CVESchema::CVE::ID
- Defined in:
- lib/cve_schema/cve/id.rb
Overview
Represents a CVE ID (ex: CVE-2021-1234
).
Instance Attribute Summary collapse
-
#number ⇒ String
readonly
The CVE number.
-
#year ⇒ String
readonly
The year the CVE ID was assigned.
Class Method Summary collapse
-
.parse(id) ⇒ Object
Parses the CVE ID.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the ID with another ID.
-
#initialize(year, number) ⇒ ID
constructor
Initializes the CVE ID.
-
#to_s ⇒ String
Converts the CVE ID back into a String.
Constructor Details
#initialize(year, number) ⇒ ID
Initializes the CVE ID.
27 28 29 30 |
# File 'lib/cve_schema/cve/id.rb', line 27 def initialize(year,number) @year = year @number = number end |
Instance Attribute Details
#number ⇒ String (readonly)
The CVE number.
16 17 18 |
# File 'lib/cve_schema/cve/id.rb', line 16 def number @number end |
#year ⇒ String (readonly)
The year the CVE ID was assigned.
11 12 13 |
# File 'lib/cve_schema/cve/id.rb', line 11 def year @year end |
Class Method Details
.parse(id) ⇒ Object
Parses the CVE ID.
41 42 43 44 45 46 47 48 49 |
# 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 |
Instance Method Details
#==(other) ⇒ Boolean
Compares the ID with another ID.
60 61 62 63 64 65 |
# File 'lib/cve_schema/cve/id.rb', line 60 def ==(other) self.class == other.class && ( @year == other.year && @number == other.number ) end |
#to_s ⇒ String
Converts the CVE ID back into a String.
73 74 75 |
# File 'lib/cve_schema/cve/id.rb', line 73 def to_s "CVE-#{@year}-#{@number}" end |