Class: CVESchema::CVE::Version

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_value:, version_name: nil, version_affected: nil) ⇒ Version

Initializes the version.

Parameters:

  • version_value (String)
  • version_name (String, nil) (defaults to: nil)
  • version_affected (nil, :'=', :'<', :'>', :'<=', , :'>=', :'!', :'!<', :'!>', :'!<=', :'!>=', :'?', :'?<', :'?>', :'?<=', :'?>=') (defaults to: nil)

    The version comparison operator. See VERSION_AFFECTED.



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_affectednil, ... (readonly)

Returns:

  • (nil, :'=', :'<', :'>', :'<=', , :'>=', :'!', :'!<', :'!>', :'!<=', :'!>=', :'?', :'?<', :'?>', :'?<=', :'?>=')


35
36
37
# File 'lib/cve_schema/cve/version.rb', line 35

def version_affected
  @version_affected
end

#version_namenil, String (readonly)

Returns:

  • (nil, String)


38
39
40
# File 'lib/cve_schema/cve/version.rb', line 38

def version_name
  @version_name
end

#version_valueString (readonly)

Returns:

  • (String)


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.

Parameters:

  • json (Hash{String => String})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The mapped Symbol Hash.

Raises:



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.

Parameters:

  • json (Hash{String => String})

    The parsed JSON.

Returns:

  • (Version)

    The loaded version object.

Raises:



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.

Returns:

  • (Boolean)


106
107
108
# File 'lib/cve_schema/cve/version.rb', line 106

def na?
  @version_value == NA
end

#to_sString

Converts the version into a String.

Returns:



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