forked from ualbertalib/sfx2sirsi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_summary_holdings.rb
64 lines (53 loc) · 1.72 KB
/
clean_summary_holdings.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require "./config_module"
#This script cleans up the summary_holdings data that I pull down from Jeremy's PHP script
#The test for this class currently tests against production data. It should be refactored to test against test data.
class SummaryHoldings
include ConfigModule
def initialize(infile_location, outfile_location)
@args = get_vars('config/util.conf')
of = create_output_file(outfile_location)
of.puts process_records(infile_location)
of.close
end
private
def create_output_file(outfile)
begin
of = File.open(outfile, "w")
rescue
raise "#{caller}: Unable to open output file."
end
of
end
def process_records(infile_location)
#records = read_input_file(infile_location).split("<line>")
records = File.open(infile_location).readlines
records.delete_at(0)
@records_hash = {}
records.each do |record|
construct_record_hash record
end
@records_hash
end
def construct_record_hash(record)
split_record = record.split(" | ").collect(&:strip)
object_id = split_record.first
free = "free" if split_record.last == "[IS_FREE]"
#summary_holdings = split_record[1].gsub(" -- ", "").strip if split_record[2]
summary_holdings = split_record[1..-2]
if object_id then
@records_hash[object_id] = {:summary_holdings=>summary_holdings, :free=>free}
#unless summary_holdings == " -- " #This conditional covers nil dates.
end
end
def read_input_file(infile_location)
file_contents = []
begin
file_contents = File.read(infile_location)
rescue
raise "Unable to open raw sfx1 data."
exit
end
file_contents
end
end
holdings = SummaryHoldings.new("data/raw_sfx1", "data/summary_holdings")