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:

  • url (String)
  • name (nil, String) (defaults to: nil)
  • refsource (nil, :MISC, String) (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:

  • (String, nil)


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:

  • (:MISC, String, nil)


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

def refsource
  @refsource
end

#urlString (readonly)

Reference URL.

Returns:

  • (String)


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:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The mapped Symbol Hash.



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:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:



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

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