added strip_text method

batch
Jeff Yates 2020-07-15 18:13:12 -04:00
parent c819d2cdbe
commit 94cd0f7eb8
1 changed files with 16 additions and 9 deletions

View File

@ -21,15 +21,6 @@ require 'json'
require 'pp' require 'pp'
require 'csv' require 'csv'
#json = File.read('./bins.json')
csv = CSV.read('./bins.csv')
text = File.read('tester.txt')
#bins = JSON.parse(json) #Turn bins.json into a hash
output = Hash.new #Creating the output storage object
bins = Hash.new
csv.each { |bin| bins[bin[0].to_sym] = bin[1..].compact }
#bin_counter expects: #bin_counter expects:
# bin - a hash with strings to search for # bin - a hash with strings to search for
# test - the document text to search through # test - the document text to search through
@ -62,6 +53,22 @@ def write_output (output)
outfile.close outfile.close
end end
#strip_text expects:
# text - the text we're working on
# start - the starting string to search for
# fin - the ending string to search for
#This method strips out all test before "start" and after "fin"
def strip_text (text, start, fin)
text.lines(start,chomp: true)[1].lines(fin,chomp: true)[0]
end
csv = CSV.read('./bins.csv')
text = File.read('tester.txt')
text = strip_text(text,'PLOVEINTAKE','PLOVECLOSING')
output = Hash.new #Creating the output storage object
bins = Hash.new #This hash stores the bins
csv.each { |bin| bins[bin[0].to_sym] = bin[1..].compact } #turn the csv array into a hash, remove nils
bins.each_key do |bin_number| bins.each_key do |bin_number|
key = bin_number.to_sym key = bin_number.to_sym
output[key] = Hash.new output[key] = Hash.new