From fa39e4d0403ac34125387c94a3467ca3b14f167d Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Sun, 22 Nov 2020 15:18:37 -0500 Subject: [PATCH] fixed NaN error when dividing by 0 --- sorter.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sorter.rb b/sorter.rb index 0ca54f1..d5b3ceb 100755 --- a/sorter.rb +++ b/sorter.rb @@ -161,7 +161,8 @@ def process_file (file_name, binfile, type) output[key] = Hash.new output[key][:words] = bin_counter(bins[bin_number], text) output[key][:total] = count_total(output[key]) - output[key][:frequency] = output[key][:total].to_f / output[:total_words].to_f + output[key][:frequency] = 0 + output[key][:frequency] = output[key][:total].to_f / output[:total_words].to_f if output[:total_words] != 0 end write_output_json(output,outfile + '-out.json') write_output_csv(output,outfile + '-out.csv')