Class: NVD::JSONFeeds::Schema::CVEFeed
- Inherits:
-
Object
- Object
- NVD::JSONFeeds::Schema::CVEFeed
- Includes:
- Enumerable, HasDataVersion
- Defined in:
- lib/nvd/json_feeds/schema/cve_feed.rb
Overview
Represents the parsed contents of a JSON CVE feed.
Constant Summary collapse
- DATA_TYPES =
{ 'CVE' => :CVE }
- DATA_FORMATS =
{ 'MITRE' => :MITRE }
Constants included from HasDataVersion
Instance Attribute Summary collapse
-
#cve_items ⇒ Array<CVEItem>
readonly
The CVE items.
-
#data_format ⇒ :MITRE
(also: #format)
readonly
The feed format.
-
#data_number_of_cves ⇒ Integer?
(also: #number_of_cves)
readonly
The number of CVEs.
-
#data_timestamp ⇒ DateTime?
(also: #timestamp)
readonly
The feed timestamp.
-
#data_type ⇒ :CVE
(also: #type)
readonly
The feed type.
Attributes included from HasDataVersion
Class Method Summary collapse
-
.from_json(json) ⇒ Hash{Symbol => Object}
Maps the parsed JSON to a Symbol Hash for #initialize.
-
.load(json) ⇒ JSONFeed
Loads the JSON feed data from the parsed JSON.
Instance Method Summary collapse
-
#each {|cve_itme| ... } ⇒ Enumerator
Enumerates over each CVE item in the feed.
-
#initialize(data_format:, data_type:, data_number_of_cves: nil, data_timestamp: nil, cve_items:, **kwargs) ⇒ CVEFeed
constructor
Initializes the JSON feed.
Methods included from HasDataVersion
Constructor Details
#initialize(data_format:, data_type:, data_number_of_cves: nil, data_timestamp: nil, cve_items:, **kwargs) ⇒ CVEFeed
Initializes the JSON feed.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 = @cve_items = cve_items end |
Instance Attribute Details
#cve_items ⇒ Array<CVEItem> (readonly)
The CVE items.
55 56 57 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 55 def cve_items @cve_items end |
#data_format ⇒ :MITRE (readonly) Also known as: format
The feed format.
27 28 29 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 27 def data_format @data_format end |
#data_number_of_cves ⇒ Integer? (readonly) Also known as: number_of_cves
The number of CVEs.
41 42 43 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 41 def data_number_of_cves @data_number_of_cves end |
#data_timestamp ⇒ DateTime? (readonly) Also known as: timestamp
The feed timestamp.
48 49 50 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 48 def @data_timestamp end |
#data_type ⇒ :CVE (readonly) Also known as: type
The feed type.
34 35 36 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 34 def data_type @data_type end |
Class Method Details
.from_json(json) ⇒ Hash{Symbol => Object}
Maps the parsed JSON to a Symbol Hash for #initialize.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# 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 ( = json['CVE_data_timestamp']) Timestamp.parse() end, cve_items: json.fetch('CVE_Items').map(&CVEItem.method(:load)) } end |
.load(json) ⇒ JSONFeed
Loads the JSON feed data from the parsed JSON.
119 120 121 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 119 def self.load(json) new(**from_json(json)) end |
Instance Method Details
#each {|cve_itme| ... } ⇒ Enumerator
Enumerates over each CVE item in the feed.
135 136 137 |
# File 'lib/nvd/json_feeds/schema/cve_feed.rb', line 135 def each(&block) @cve_items.each(&block) end |