diff --git a/sorter.rb b/sorter.rb index d14b633..5f629bf 100755 --- a/sorter.rb +++ b/sorter.rb @@ -111,6 +111,12 @@ def split_text (text, start, fin) return ret end +#process_file expects: +# file_name - the name of the file to process +# binfile - the name of the bin file (csv) to use +# type - which type of file are we processing, must be 'pn' or 'iat' +# +#This method is the meat and potatos. Preforms the text stripping, word counting, and creates output files. def process_file (file_name, binfile, type) csv = CSV.read(binfile) text = File.read(file_name) @@ -130,7 +136,19 @@ def process_file (file_name, binfile, type) end write_output_json(output,outfile + '-out.json') write_output_csv(output,outfile + '-out.csv') +end +#process_dir expects: +# dir_name - a direcroty containing text files to process +# binfile - the name of the bin file +# type - which type of file are we processing, must be 'pn' or 'iat' +# +#This method will process all .txt files in the supplied directory +def process_dir(dir_name, binfile, type) + Dir.glob(dir_name + '*.txt') do |file_name| + puts file_name + process_file(file_name, binfile, type) + end end options = Hash.new @@ -145,7 +163,7 @@ OptionParser.new do |opts| opts.on("-b", "--bin-file binfile", "Name of the bin file") do |binfile| options[:binfile] = binfile end - opts.on("-d", "--directoy dir", "Directory containing text files to process") do |dir| + opts.on("-d", "--directory dir", "Directory containing text files to process") do |dir| options[:dir] = dir end end.parse! @@ -154,5 +172,7 @@ if options[:file] && options[:dir] puts "Invalid options, you must either a file or a directoy of files." elsif options[:file] process_file(options[:file], options[:binfile], options[:type]) +elsif options[:dir] + process_dir(options[:dir], options[:binfile], options[:type]) end