From 86707e1eb95a0b2ba386c0b000274df23ba54970 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 16 Mar 2022 07:40:38 -0400 Subject: bin/cisa-sizes.rb: get field min size --- bin/cisa-sizes.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bin/cisa-sizes.rb') diff --git a/bin/cisa-sizes.rb b/bin/cisa-sizes.rb index 88ec7d3..934ac23 100755 --- a/bin/cisa-sizes.rb +++ b/bin/cisa-sizes.rb @@ -1,8 +1,7 @@ #!/usr/bin/env ruby # -# cisa-sizes.rb: get maximum field lengths from compressed cisa -# kev catalog. +# cisa-sizes.rb: get min/max field lengths from cisa catalog. # require 'json' @@ -14,7 +13,10 @@ PATH = File.join(__dir__, '../cisa/testdata/cisa-kevc-20220313.json.gz') # read vulns ROWS = JSON(Zlib::GzipReader.new(File.open(PATH)).read)['vulnerabilities'] -# get/print json-encoded maximum field lengths -puts JSON(ROWS.each.with_object(Hash.new { |h, k| h[k] = 0 }) do |row, r| - row.each { |k, v| r[k] = v.size if v.size > r[k] } +# get/print json-encoded min/max field lengths +puts JSON(ROWS.each.with_object(Hash.new { |h, k| h[k] = {} }) do |row, r| + row.each do |k, v| + r[k][:min] = v.size if !r[k][:min] || v.size < r[k][:min] + r[k][:max] = v.size if !r[k][:max] || v.size > r[k][:max] + end end) -- cgit v1.2.3