Class: CVESchema::CVE::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/cve_schema/cve/reference.rb

Overview

Represents a reference object within the "reference_data" JSON Array.

Constant Summary collapse

REFSOURCES =
{
  'MISC' => :MISC
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, name: nil, refsource: nil) ⇒ Reference

Initializes the reference.

Parameters:

  • (defaults to: nil)
  • (defaults to: nil)


41
42
43
44
45
# File 'lib/cve_schema/cve/reference.rb', line 41

def initialize(url: , name: nil, refsource: nil)
  @url = url
  @name = name
  @refsource = refsource
end

Instance Attribute Details

#nameString? (readonly)

Optional reference name.

Returns:



18
19
20
# File 'lib/cve_schema/cve/reference.rb', line 18

def name
  @name
end

#refsource:MISC, ... (readonly) Also known as: ref_source

Optional reference source identifier.

Returns:



28
29
30
# File 'lib/cve_schema/cve/reference.rb', line 28

def refsource
  @refsource
end

#urlString (readonly)

Reference URL.

Returns:



13
14
15
# File 'lib/cve_schema/cve/reference.rb', line 13

def url
  @url
end

Class Method Details

.from_json(json) ⇒ Hash{Symbol => Object}

Maps the parsed JSON to a Symbol Hash for #initialize.

Parameters:

  • The parsed JSON.

Returns:

  • The mapped Symbol Hash.

API:

  • semipublic



58
59
60
61
62
63
64
# File 'lib/cve_schema/cve/reference.rb', line 58

def self.from_json(json)
  {
    url:  json['url'],
    name: json['name'],
    refsource: REFSOURCES[json['refsource']]
  }
end

.load(json) ⇒ Reference

Loads the reference from the parsed JSON.

Parameters:

  • The parsed JSON.

Returns:

API:

  • semipublic



76
77
78
# File 'lib/cve_schema/cve/reference.rb', line 76

def self.load(json)
  new(**from_json(json))
end