class NVD::JSONFeeds::Schema::CVEFeed

Represents the parsed contents of a JSON CVE feed.

Constants

DATA_FORMATS
DATA_TYPES

Attributes

cve_items[R]

The CVE items.

@return [Array<CVEItem>]

data_format[R]

The feed format.

@return [:MITRE]

data_number_of_cves[R]

The number of CVEs.

@return [Integer, nil]

data_timestamp[R]

The feed timestamp.

@return [DateTime, nil]

data_type[R]

The feed type.

@return [:CVE]

format[R]

The feed format.

@return [:MITRE]

number_of_cves[R]

The number of CVEs.

@return [Integer, nil]

timestamp[R]

The feed timestamp.

@return [DateTime, nil]

type[R]

The feed type.

@return [:CVE]

Public Class Methods

from_json(json) click to toggle source

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

@param [Hash{String => Object}] json

The parsed JSON.

@return [Hash{Symbol => Object}]

The mapped Symbol Hash.
Calls superclass method
# File lib/nvd/json_feeds/schema/cve_feed.rb, line 94
def self.from_json(json)
  {
    data_type:   DATA_TYPES.fetch(json.fetch('CVE_data_type')),
    data_format: DATA_FORMATS.fetch(json.fetch('CVE_data_format')),
    **super(json),

    data_number_of_cves: json.fetch('CVE_data_numberOfCVEs').to_i,

    data_timestamp: if (timestamp = json['CVE_data_timestamp'])
                      Timestamp.parse(timestamp)
                    end,

    cve_items: json.fetch('CVE_Items').map(&CVEItem.method(:load))
  }
end
load(json) click to toggle source

Loads the JSON feed data from the parsed JSON.

@param [Hash{String => Object}] json

The parsed JSON.

@return [JSONFeed]

The loaded JSON data.
# File lib/nvd/json_feeds/schema/cve_feed.rb, line 119
def self.load(json)
  new(**from_json(json))
end
new(data_format: , data_type: , data_number_of_cves: nil, data_timestamp: nil, cve_items: , **kwargs) click to toggle source

Initializes the JSON feed.

@param [:MITRE] data_format

@param [:CVE] data_type

@param [Integer, nil] data_number_of_cves

@param [DateTime, nil] data_timestamp

@param [Array<CVEItem>] cve_items

# File lib/nvd/json_feeds/schema/cve_feed.rb, line 70
def initialize(data_format: , data_type: , data_number_of_cves: nil,
                                           data_timestamp: nil,
                                           cve_items: ,
                                           **kwargs)
  super(**kwargs)

  @data_format = data_format
  @data_type   = data_type

  @data_number_of_cves = data_number_of_cves
  @data_timestamp      = data_timestamp

  @cve_items = cve_items
end

Public Instance Methods

each(&block) click to toggle source

Enumerates over each CVE item in the feed.

@yield [cve_itme]

The given block will be passed each CVE Item.

@yieldparam [CVEItem] cve_item

A CVE Item in the feed.

@return [Enumerator]

If no block is given, an enumerator will be returned.
# File lib/nvd/json_feeds/schema/cve_feed.rb, line 135
def each(&block)
  @cve_items.each(&block)
end