-
Notifications
You must be signed in to change notification settings - Fork 0
/
element-union-multi.rb
executable file
·52 lines (39 loc) · 1.2 KB
/
element-union-multi.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
#!/usr/bin/env ruby
# For each element in an XML file, this script outputs the union of
# the element attributes and element children found for every instance
# of the element.
require_relative '../lib/nyudl/ead'
if ARGV.length != 1
$stderr.puts "ERROR: incorrect argument count"
$stderr.puts "usage: #{$0} <path to file containing paths of EADs to include in analysis>"
$stderr.puts " e.g.: #{$0} file-list.txt"
exit 1
end
paths_file = ARGV.shift
unless File.file?(paths_file)
$stderr.puts "ERROR: file '#{paths_file}' does not exist"
exit 1
end
grand_master_hash = {}
global_status = 0
File.foreach(paths_file) do | file |
file.chomp!
unless File.file?(file)
$stderr.puts "ERROR: file '#{file}' does not exist"
global_status = 1
next
end
$stderr.puts "processing #{file}"
doc = Nokogiri::XML(File.open(file)) {|conf| conf.noblanks}
hash = NYUDL::EAD::Analyzer.run(doc.root)
hash.keys.each do |k|
if grand_master_hash[k].nil?
grand_master_hash[k] = hash[k]
else
grand_master_hash[k].merge(hash[k])
end
end
end
puts NYUDL::EAD::AnalysisNode.header_string
grand_master_hash.keys.sort.each { |k| puts grand_master_hash[k].to_s }
exit global_status