added directory/batch processing
parent
f7f95b6b93
commit
a60395dd5b
22
sorter.rb
22
sorter.rb
|
@ -111,6 +111,12 @@ def split_text (text, start, fin)
|
||||||
return ret
|
return ret
|
||||||
end
|
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)
|
def process_file (file_name, binfile, type)
|
||||||
csv = CSV.read(binfile)
|
csv = CSV.read(binfile)
|
||||||
text = File.read(file_name)
|
text = File.read(file_name)
|
||||||
|
@ -130,7 +136,19 @@ def process_file (file_name, binfile, type)
|
||||||
end
|
end
|
||||||
write_output_json(output,outfile + '-out.json')
|
write_output_json(output,outfile + '-out.json')
|
||||||
write_output_csv(output,outfile + '-out.csv')
|
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
|
end
|
||||||
|
|
||||||
options = Hash.new
|
options = Hash.new
|
||||||
|
@ -145,7 +163,7 @@ OptionParser.new do |opts|
|
||||||
opts.on("-b", "--bin-file binfile", "Name of the bin file") do |binfile|
|
opts.on("-b", "--bin-file binfile", "Name of the bin file") do |binfile|
|
||||||
options[:binfile] = binfile
|
options[:binfile] = binfile
|
||||||
end
|
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
|
options[:dir] = dir
|
||||||
end
|
end
|
||||||
end.parse!
|
end.parse!
|
||||||
|
@ -154,5 +172,7 @@ if options[:file] && options[:dir]
|
||||||
puts "Invalid options, you must either a file or a directoy of files."
|
puts "Invalid options, you must either a file or a directoy of files."
|
||||||
elsif options[:file]
|
elsif options[:file]
|
||||||
process_file(options[:file], options[:binfile], options[:type])
|
process_file(options[:file], options[:binfile], options[:type])
|
||||||
|
elsif options[:dir]
|
||||||
|
process_dir(options[:dir], options[:binfile], options[:type])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue