From 96740f161ac498c03437ad8bf218f88bac1fa943 Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Wed, 22 Jul 2020 15:17:54 -0400 Subject: [PATCH] changed output file --- sorter.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sorter.rb b/sorter.rb index 9d3ca45..06c7198 100755 --- a/sorter.rb +++ b/sorter.rb @@ -48,8 +48,8 @@ end #write_output expects: # output - a hash containing all of our output #This method converts the output hash to JSON and writes it to output.json -def write_output (output) - outfile = File.open('./output.json','w') +def write_output (output, filename) + outfile = File.open(filename,'w') outfile.write(output.to_json) outfile.close end @@ -73,11 +73,12 @@ end.parse! csv = CSV.read('./bins.csv') -text = File.read('tester.txt') text = File.read(options[:file]) text = strip_text(text,'PLOVEINTAKE','PLOVECLOSING') output = Hash.new #Creating the output storage object bins = Hash.new #This hash stores the bins +outfile = options[:file] + '-out.json' +outfile.slice!('.txt') csv.each { |bin| bins[bin[0]] = bin[1..].compact } #turn the csv array into a hash, remove nils @@ -87,5 +88,5 @@ bins.each_key do |bin_number| output[key][:words] = bin_counter(bins[bin_number], text) output[key][:total] = count_total(output[key]) end -write_output(output) +write_output(output,outfile)