Class: NVD::JSONFeeds::Meta

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

Overview

Represents the parsed contents of a .meta file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(last_modified_date, size, zip_size, gz_size, sha256) ⇒ Meta

Initializes the feed metadata.

Parameters:

  • The parsed lastModifiedDate timestamp.

  • The size value.

  • The zipSize value.

  • The gzSize value.

  • The sha256 value.



56
57
58
59
60
61
62
63
# File 'lib/nvd/json_feeds/meta.rb', line 56

def initialize(last_modified_date,size,zip_size,gz_size,sha256)
  @last_modified_date = last_modified_date

  @size     = size
  @zip_size = zip_size
  @gz_size  = gz_size
  @sha256   = sha256
end

Instance Attribute Details

#gz_sizeInteger (readonly)

The size of the .gz feed file.

Returns:



30
31
32
# File 'lib/nvd/json_feeds/meta.rb', line 30

def gz_size
  @gz_size
end

#last_modified_dateDateTime (readonly)

The date the feed file was last updated.

Returns:



15
16
17
# File 'lib/nvd/json_feeds/meta.rb', line 15

def last_modified_date
  @last_modified_date
end

#sha256String (readonly)

Note:

NVD uses all upper-case SHA256 checksums.

The SHA256 checksum of the uncompressed .json feed file.

Returns:



36
37
38
# File 'lib/nvd/json_feeds/meta.rb', line 36

def sha256
  @sha256
end

#sizeInteger (readonly)

The size of the uncompressed .json feed file.

Returns:



20
21
22
# File 'lib/nvd/json_feeds/meta.rb', line 20

def size
  @size
end

#zip_sizeInteger (readonly)

The size of the .zip feed file.

Returns:



25
26
27
# File 'lib/nvd/json_feeds/meta.rb', line 25

def zip_size
  @zip_size
end

Class Method Details

.parse(string) ⇒ Meta

Parses the text.

Parameters:

  • The raw meta string.

Returns:

  • The parsed meta information.

Raises:

  • The meta string was malformed.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/nvd/json_feeds/meta.rb', line 77

def self.parse(string)
  last_modified_date = nil
  size     = nil
  zip_size = nil
  gz_size  = nil
  sha256   = nil

  string.each_line do |line|
    name, value = line.chomp.split(':',2)

    case name
    when 'lastModifiedDate'
      last_modified_date = DateTime.parse(value)
    when 'size'    then size     = value.to_i
    when 'zipSize' then zip_size = value.to_i
    when 'gzSize'  then gz_size  = value.to_i
    when 'sha256'  then sha256   = value
    end
  end

  unless last_modified_date
    raise(MetaParseError,"lastModifiedDate missing")
  end

  unless size
    raise(MetaParseError,"size entry missing")
  end

  unless zip_size
    raise(MetaParseError,"zipSize entry missing")
  end

  unless gz_size
    raise(MetaParseError,"gzSize entry missing")
  end

  unless sha256
    raise(MetaParseError,"sha256 entry missing")
  end

  return new(last_modified_date,size,zip_size,gz_size,sha256)
end