Class: NVD::JSONFeeds::FeedFile
- Inherits:
-
Object
- Object
- NVD::JSONFeeds::FeedFile
- Defined in:
- lib/nvd/json_feeds/feed_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
The path to the feed file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ FeedFile
constructor
Initializes the feed file.
-
#inspect ⇒ String
Inspects the feed file.
-
#json ⇒ Hash{String => Object}
Parses the JSON.
-
#parse ⇒ CVEFeed
Loads the CVE data from the feed file.
-
#read ⇒ String
abstract
Reads the feed file.
-
#sha256 ⇒ String
Calculates the SHA256 checksum of the feed file.
-
#to_s ⇒ String
Converts the feed file to a String.
Constructor Details
#initialize(path) ⇒ FeedFile
Initializes the feed file.
21 22 23 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 21 def initialize(path) @path = File.(path) end |
Instance Attribute Details
#path ⇒ String (readonly)
The path to the feed file.
13 14 15 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 13 def path @path end |
Class Method Details
.parse(path) ⇒ Object
28 29 30 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 28 def self.parse(path) new(path).parse end |
Instance Method Details
#inspect ⇒ String
Inspects the feed file.
89 90 91 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 89 def inspect "#<#{self.class}: #{self}>" end |
#json ⇒ Hash{String => Object}
Parses the JSON.
60 61 62 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 60 def json MultiJson.load(read) end |
#parse ⇒ CVEFeed
Loads the CVE data from the feed file.
70 71 72 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 70 def parse Schema::CVEFeed.load(json) end |
#read ⇒ String
This method is abstract.
Reads the feed file.
50 51 52 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 50 def read raise(NotImplementedError,"#{self.class}#read not implemented") end |
#sha256 ⇒ String
Note:
NVD uses all upper-case SHA256 checksums.
Calculates the SHA256 checksum of the feed file.
39 40 41 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 39 def sha256 Digest::SHA256.hexdigest(read).upcase end |
#to_s ⇒ String
Converts the feed file to a String.
80 81 82 |
# File 'lib/nvd/json_feeds/feed_file.rb', line 80 def to_s @path end |