Class: NVDFeedScraper::Meta
- Inherits:
-
Object
- Object
- NVDFeedScraper::Meta
- Defined in:
- lib/nvd_feed_api/meta.rb
Overview
Manage the meta file from a feed.
== Usage
Several ways to set the url:
m = NVDFeedScraper::Meta.new(metaUrl)
m.parse
or
m = NVDFeedScraper::Meta.new
m.url = metaUrl
m.parse
or
m = NVDFeedScraper::Meta.new
m.parse(metaUrl)
Instance Attribute Summary collapse
-
#gz_size ⇒ String
readonly
Meta gz size getter.
-
#last_modified_date ⇒ String
readonly
Meta last modified date getter.
-
#sha256 ⇒ String
readonly
Meta JSON sha256 getter.
-
#size ⇒ String
readonly
Meta JSON size getter.
-
#url ⇒ String
Meta URL getter.
-
#zip_size ⇒ String
readonly
Meta zip size getter.
Instance Method Summary collapse
-
#initialize(url = nil) ⇒ Meta
constructor
A new instance of Meta.
-
#parse(*arg) ⇒ Object
Parse the meta file from the URL and set the attributes.
Constructor Details
#initialize(url = nil) ⇒ Meta
Returns a new instance of Meta.
63 64 65 |
# File 'lib/nvd_feed_api/meta.rb', line 63 def initialize(url = nil) @url = url end |
Instance Attribute Details
#gz_size ⇒ String (readonly)
NVDFeedScraper::Meta gz size getter
54 55 56 |
# File 'lib/nvd_feed_api/meta.rb', line 54 def gz_size @gz_size end |
#last_modified_date ⇒ String (readonly)
NVDFeedScraper::Meta last modified date getter
36 37 38 |
# File 'lib/nvd_feed_api/meta.rb', line 36 def last_modified_date @last_modified_date end |
#sha256 ⇒ String (readonly)
NVDFeedScraper::Meta JSON sha256 getter
60 61 62 |
# File 'lib/nvd_feed_api/meta.rb', line 60 def sha256 @sha256 end |
#size ⇒ String (readonly)
NVDFeedScraper::Meta JSON size getter
42 43 44 |
# File 'lib/nvd_feed_api/meta.rb', line 42 def size @size end |
#url ⇒ String
NVDFeedScraper::Meta URL getter.
69 70 71 |
# File 'lib/nvd_feed_api/meta.rb', line 69 def url @url end |
#zip_size ⇒ String (readonly)
NVDFeedScraper::Meta zip size getter
48 49 50 |
# File 'lib/nvd_feed_api/meta.rb', line 48 def zip_size @zip_size end |
Instance Method Details
#parse ⇒ Integer #parse(url) ⇒ Integer
Parse the meta file from the URL and set the attributes.
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 |
# File 'lib/nvd_feed_api/meta.rb', line 87 def parse(*arg) if arg.length == 1 # arg = url self.url = arg[0] elsif arg.length > 1 raise 'Too much arguments' end raise "Can't parse if the URL is empty" if @url.nil? uri = URI(@url) = Net::HTTP.get(uri) = .split.to_h { |x| x.split(':', 2) } raise 'no lastModifiedDate attribute found' unless ['lastModifiedDate'] raise 'no valid size attribute found' unless /[0-9]+/.match?(['size']) raise 'no valid zipSize attribute found' unless /[0-9]+/.match?(['zipSize']) raise 'no valid gzSize attribute found' unless /[0-9]+/.match?(['gzSize']) raise 'no valid sha256 attribute found' unless /[0-9A-F]{64}/.match?(['sha256']) @last_modified_date = ['lastModifiedDate'] @size = ['size'] @zip_size = ['zipSize'] @gz_size = ['gzSize'] @sha256 = ['sha256'] 0 end |