From fa25c05ab916b6c1830b2c6ef30fae71a21826d7 Mon Sep 17 00:00:00 2001 From: booboy Date: Thu, 13 Jun 2019 00:31:12 -0500 Subject: [PATCH] made method to extract metadata into json --- classes/nvd_downloader.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/classes/nvd_downloader.rb b/classes/nvd_downloader.rb index 26d0e32..4b4cf58 100644 --- a/classes/nvd_downloader.rb +++ b/classes/nvd_downloader.rb @@ -75,7 +75,7 @@ module NvdTools # of all of the json.gz from each year + recent + modified json feeds end - def modified_meta(filename) + def get_metadata_file(filename) file = filenames('meta').select do |name| name == filename end.first @@ -85,18 +85,26 @@ module NvdTools # this should be a method that builds # the modified filename with the meta file extension included end - - def check_metafile(metafile) - # open the metafile, build a hash of k/v pairs of the data inside of the file + def extract_metadata(metadata) + metaf = get_metadata_file(metadata) + keys_and_values_str = metaf.map do |line| + line.split(":", 2) + end + json = Hash[keys_and_values_str].to_json + JSON.parse(json, { symbolize_names: true }) + end + + def check_metadata(metadata_file_to_check, metadata_to_check_against) # check each k/v pair against the file on disk # return a new hash with the same k as before, but the value being a boolean true or false if the value from the k/v pair + end - - def detect_changes(metafile) - # this should be a method that detects changes in the metafile. - # run the check_metafile method against the current metafile on disk. + + def detect_changes(metadata) + # this should be a method that detects changes in the metadata. + # run the check_metadata method against the current metadata. # if there is a change, return true, if not return false end end -end +end \ No newline at end of file