made method to extract metadata into json

This commit is contained in:
booboy 2019-06-13 00:31:12 -05:00
parent 4736d84e7d
commit fa25c05ab9

View file

@ -75,7 +75,7 @@ module NvdTools
# of all of the json.gz from each year + recent + modified json feeds # of all of the json.gz from each year + recent + modified json feeds
end end
def modified_meta(filename) def get_metadata_file(filename)
file = filenames('meta').select do |name| file = filenames('meta').select do |name|
name == filename name == filename
end.first end.first
@ -86,16 +86,24 @@ module NvdTools
# the modified filename with the meta file extension included # the modified filename with the meta file extension included
end end
def check_metafile(metafile) def extract_metadata(metadata)
metaf = get_metadata_file(metadata)
# open the metafile, build a hash of k/v pairs of the data inside of the file keys_and_values_str = metaf.map do |line|
# check each k/v pair against the file on disk line.split(":", 2)
# 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
json = Hash[keys_and_values_str].to_json
JSON.parse(json, { symbolize_names: true })
end end
def detect_changes(metafile) def check_metadata(metadata_file_to_check, metadata_to_check_against)
# this should be a method that detects changes in the metafile. # check each k/v pair against the file on disk
# run the check_metafile method against the current metafile 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(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 # if there is a change, return true, if not return false
end end
end end