From f0ac211916ed8d5451fdbf655091db198e951277 Mon Sep 17 00:00:00 2001 From: Bryan Karaffa Date: Mon, 27 Nov 2023 11:30:42 -0800 Subject: [PATCH] fix: convert nil values to empty string "" (#1645) --- .../generate_readme_policy_table_of_contents.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/readme_policy_table_of_contents/generate_readme_policy_table_of_contents.rb b/tools/readme_policy_table_of_contents/generate_readme_policy_table_of_contents.rb index 1a14f1e555..935a1374f6 100644 --- a/tools/readme_policy_table_of_contents/generate_readme_policy_table_of_contents.rb +++ b/tools/readme_policy_table_of_contents/generate_readme_policy_table_of_contents.rb @@ -31,10 +31,20 @@ # Construct the policy hash with just the info we need for the output p = {file: file, name: pp.parsed_name, category: pp.parsed_category, provider: pp.parsed_info[:provider], service: pp.parsed_info[:service], policy_set: pp.parsed_info[:policy_set], recommendation_type: pp.parsed_info[:recommendation_type]} + + ## Check that all keys/values are not nil + p.each do |key, value| + if value.nil? then p[key] = "" end + end + + # Check if the pt_stats counters have been initialized yet + # If not, initialize them with count starting at 0 if pt_stats[:categories][p[:category]].nil? then pt_stats[:categories][p[:category]] = 0 end if pt_stats[:providers][p[:provider]].nil? then pt_stats[:providers][p[:provider]] = 0 end if pt_stats[:services][p[:service]].nil? then pt_stats[:services][p[:service]] = 0 end if pt_stats[:policy_sets][p[:policy_set]].nil? then pt_stats[:policy_sets][p[:policy_set]] = 0 end + + # Increment the stats for the policy pt_stats[:categories][p[:category]] += 1 pt_stats[:providers][p[:provider]] += 1 pt_stats[:services][p[:service]] += 1