accept file from stdin

batch
Jeff Yates 2020-07-21 18:56:46 -04:00
parent 85ca5fe2e1
commit c9b78d4cfc
1 changed files with 11 additions and 0 deletions

View File

@ -20,6 +20,7 @@
require 'json' require 'json'
require 'pp' require 'pp'
require 'csv' require 'csv'
require 'optparse'
#bin_counter expects: #bin_counter expects:
# bin - a hash with strings to search for # bin - a hash with strings to search for
@ -62,8 +63,18 @@ def strip_text (text, start, fin)
text.lines(start,chomp: true)[1].lines(fin,chomp: true)[0] text.lines(start,chomp: true)[1].lines(fin,chomp: true)[0]
end end
options = Hash.new
OptionParser.new do |opts|
opts.banner = 'sorter.rb --options'
opts.on("-f", "--file file", "Name of the file to process") do |file|
options[:file] = file
end
end.parse!
csv = CSV.read('./bins.csv') csv = CSV.read('./bins.csv')
text = File.read('tester.txt') text = File.read('tester.txt')
text = File.read(options[:file])
text = strip_text(text,'PLOVEINTAKE','PLOVECLOSING') text = strip_text(text,'PLOVEINTAKE','PLOVECLOSING')
output = Hash.new #Creating the output storage object output = Hash.new #Creating the output storage object
bins = Hash.new #This hash stores the bins bins = Hash.new #This hash stores the bins