Class: NVD::JSONFeeds::FeedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/nvd/json_feeds/feed_file.rb

Direct Known Subclasses

GzFeedFile, JSONFeedFile, ZipFeedFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FeedFile

Initializes the feed file.

Parameters:

  • path (String)

    The path to the feed file.



21
22
23
# File 'lib/nvd/json_feeds/feed_file.rb', line 21

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathString (readonly)

The path to the feed file.

Returns:

  • (String)


13
14
15
# File 'lib/nvd/json_feeds/feed_file.rb', line 13

def path
  @path
end

Class Method Details

.parse(path) ⇒ Object

See Also:



28
29
30
# File 'lib/nvd/json_feeds/feed_file.rb', line 28

def self.parse(path)
  new(path).parse
end

Instance Method Details

#inspectString

Inspects the feed file.

Returns:

  • (String)


89
90
91
# File 'lib/nvd/json_feeds/feed_file.rb', line 89

def inspect
  "#<#{self.class}: #{self}>"
end

#jsonHash{String => Object}

Parses the JSON.

Returns:

  • (Hash{String => Object})

    The parsed JSON.



60
61
62
# File 'lib/nvd/json_feeds/feed_file.rb', line 60

def json
  MultiJson.load(read)
end

#parseCVEFeed

Loads the CVE data from the feed file.

Returns:

  • (CVEFeed)

    The CVE feed data.



70
71
72
# File 'lib/nvd/json_feeds/feed_file.rb', line 70

def parse
  Schema::CVEFeed.load(json)
end

#readString

This method is abstract.

Reads the feed file.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/nvd/json_feeds/feed_file.rb', line 50

def read
  raise(NotImplementedError,"#{self.class}#read not implemented")
end

#sha256String

Note:

NVD uses all upper-case SHA256 checksums.

Calculates the SHA256 checksum of the feed file.

Returns:

  • (String)


39
40
41
# File 'lib/nvd/json_feeds/feed_file.rb', line 39

def sha256
  Digest::SHA256.hexdigest(read).upcase
end

#to_sString

Converts the feed file to a String.

Returns:

  • (String)

    The feed file path.



80
81
82
# File 'lib/nvd/json_feeds/feed_file.rb', line 80

def to_s
  @path
end