Class: CVEList::CVE

Inherits:
CVESchema::CVE
  • Object
show all
Defined in:
lib/cvelist/cve.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, **kwargs) ⇒ CVE

Initializes the CVE.

Parameters:

  • path (String)

    The path to the CVE JSON.



22
23
24
25
26
# File 'lib/cvelist/cve.rb', line 22

def initialize(path, **kwargs)
  super(**kwargs)

  @path = path
end

Instance Attribute Details

#pathString (readonly)

The path to the CVE JSON.

Returns:

  • (String)


14
15
16
# File 'lib/cvelist/cve.rb', line 14

def path
  @path
end

Class Method Details

.load(file) ⇒ CVE

Loads the CVE JSON from the given file.

Parameters:

  • file (String)

    The path to the file.

Returns:

  • (CVE)

    The loaded CVE object.

Raises:



78
79
80
# File 'lib/cvelist/cve.rb', line 78

def self.load(file)
  new(file, **from_json(read(file)))
end

.parse(json) ⇒ Hash{String => Object}

Parses the given JSON.

Parameters:

  • json (String)

    The raw JSON.

Returns:

  • (Hash{String => Object})

    The parsed JSON.

Raises:

  • (InvalidJSON)

    Could not parse the JSON in the given file.



42
43
44
45
46
# File 'lib/cvelist/cve.rb', line 42

def self.parse(json)
  MultiJson.load(json)
rescue MultiJson::ParseError => error
  raise(InvalidJSON,error.message)
end

.read(file) ⇒ Hash{String => Object}

Parses the JSON in the given file.

Parameters:

  • file (String)

    The path to the file.

Returns:

  • (Hash{String => Object})

    The parsed JSON.

Raises:

  • (InvalidJSON)

    Could not parse the JSON in the given file.



62
63
64
# File 'lib/cvelist/cve.rb', line 62

def self.read(file)
  parse(File.read(file))
end