Class: CVESchema::CVE::Version
- Inherits:
-
Object
- Object
- CVESchema::CVE::Version
- Defined in:
- lib/cve_schema/cve/version.rb
Overview
Represents an element within the "version_data"
JSON Array.
Constant Summary collapse
- VERSION_AFFECTED =
{ '=' => :"=", # affects version_value '<' => :"<", # affects versions prior to version_value '>' => :">", # affects versions later than version_value '<=' => :"<=", # affects version_value and prior versions '>=' => :">=", # affects version_value and later versions '!' => :"!", # doesn't affect version_value '!<' => :"!<", # doesn't affect versions prior to version_value '!>' => :"!>", # doesn't affect versions later than version_value '!<=' => :"!<=",# doesn't affect version_value and prior versions '!>=' => :"!>=",# doesn't affect version_value and later versions '?' => :"?", # status of version_value is unknown '?<' => :"?<", # status of versions prior to version_value is unknown '?>' => :"?>", # status of versions later than version_value is unknown '?<=' => :"?<=",# status of version_value and prior versions is unknown '?>=' => :"?>=",# status of version_value and later versions is unknown }
Instance Attribute Summary collapse
- #version_affected ⇒ nil, ... readonly
- #version_name ⇒ nil, String readonly
- #version_value ⇒ String readonly
Class Method Summary collapse
-
.from_json(json) ⇒ Hash{Symbol => Object}
Maps the parsed JSON to a Symbol Hash for #initialize.
-
.load(json) ⇒ Version
Loads the version object from parsed JSON.
Instance Method Summary collapse
-
#initialize(version_value:, version_name: nil, version_affected: nil) ⇒ Version
constructor
Initializes the version.
-
#na? ⇒ Boolean
Determines if the #version_value is
n/a
. -
#to_s ⇒ String
Converts the version into a String.
Constructor Details
#initialize(version_value:, version_name: nil, version_affected: nil) ⇒ Version
Initializes the version.
50 51 52 53 54 |
# File 'lib/cve_schema/cve/version.rb', line 50 def initialize(version_value: , version_name: nil, version_affected: nil) @version_value = version_value @version_name = version_name @version_affected = version_affected end |
Instance Attribute Details
#version_affected ⇒ nil, ... (readonly)
35 36 37 |
# File 'lib/cve_schema/cve/version.rb', line 35 def version_affected @version_affected end |
#version_name ⇒ nil, String (readonly)
38 39 40 |
# File 'lib/cve_schema/cve/version.rb', line 38 def version_name @version_name end |
#version_value ⇒ String (readonly)
14 15 16 |
# File 'lib/cve_schema/cve/version.rb', line 14 def version_value @version_value end |
Class Method Details
.from_json(json) ⇒ Hash{Symbol => Object}
Maps the parsed JSON to a Symbol Hash for #initialize.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cve_schema/cve/version.rb', line 70 def self.from_json(json) { version_affected: if (version_affected = json['version_affected']) VERSION_AFFECTED.fetch(version_affected) do raise UnknownJSONValue.new('version_affected',version_affected) end end, version_name: json['version_name'], version_value: json['version_value'] } end |
.load(json) ⇒ Version
Loads the version object from parsed JSON.
97 98 99 |
# File 'lib/cve_schema/cve/version.rb', line 97 def self.load(json) new(**from_json(json)) end |
Instance Method Details
#na? ⇒ Boolean
Determines if the #version_value is n/a
.
106 107 108 |
# File 'lib/cve_schema/cve/version.rb', line 106 def na? @version_value == NA end |
#to_s ⇒ String
Converts the version into a String.
116 117 118 119 120 121 122 |
# File 'lib/cve_schema/cve/version.rb', line 116 def to_s if @version_affected "#{@version_affected} #{@version_value}" else @version_value end end |