class NVD::JSONFeeds::FeedFile

Attributes

path[R]

The path to the feed file.

@return [String]

Public Class Methods

new(path) click to toggle source

Initializes the feed file.

@param [String] path

The path to the feed file.
# File lib/nvd/json_feeds/feed_file.rb, line 21
def initialize(path)
  @path = File.expand_path(path)
end
parse(path) click to toggle source

@see parse

# File lib/nvd/json_feeds/feed_file.rb, line 28
def self.parse(path)
  new(path).parse
end

Public Instance Methods

inspect() click to toggle source

Inspects the feed file.

@return [String]

# File lib/nvd/json_feeds/feed_file.rb, line 89
def inspect
  "#<#{self.class}: #{self}>"
end
json() click to toggle source

Parses the JSON.

@return [Hash{String => Object}]

The parsed JSON.
# File lib/nvd/json_feeds/feed_file.rb, line 60
def json
  MultiJson.load(read)
end
parse() click to toggle source

Loads the CVE data from the feed file.

@return [CVEFeed]

The CVE feed data.
# File lib/nvd/json_feeds/feed_file.rb, line 70
def parse
  Schema::CVEFeed.load(json)
end
read() click to toggle source

Reads the feed file.

@return [String]

@abstract

# File lib/nvd/json_feeds/feed_file.rb, line 50
def read
  raise(NotImplementedError,"#{self.class}#read not implemented")
end
sha256() click to toggle source

Calculates the SHA256 checksum of the feed file.

@return [String]

@note NVD uses all upper-case SHA256 checksums.

# File lib/nvd/json_feeds/feed_file.rb, line 39
def sha256
  Digest::SHA256.hexdigest(read).upcase
end
to_s() click to toggle source

Converts the feed file to a String.

@return [String]

The feed file path.
# File lib/nvd/json_feeds/feed_file.rb, line 80
def to_s
  @path
end