Last active
January 16, 2020 11:48
-
-
Save masao/eff3ee10b7b7a4dad656e8ac8d46421e to your computer and use it in GitHub Desktop.
see newer version at https://gist.github.com/masao/10db0c36da39f23106a70518be4cf926
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
data = {} | |
bibdata = {} | |
holdings = {} | |
ARGF.each do |line| | |
line.chomp! | |
line.scan(/(?:\w+=(?:.*?)|<\/?\w+\>) /).each do |element| | |
case element | |
when /\A(\w+)=(.+)\Z/ | |
key = $1.downcase.intern | |
val = $2.chop | |
data[key] = val | |
case key | |
when :id | |
data[:ncid] = val | |
when :trd | |
data[:trd_title], data[:trd_author], = data[:trd].split(/ \/ /) | |
end | |
end | |
end | |
case data[:_dbname_] | |
when "BOOK" | |
bibdata[data[:ncid]] = data | |
when "BHOLD" | |
holdings[data[:bid]] ||= [] | |
holdings[data[:bid]] << data | |
end | |
data = {} | |
end | |
bibdata.sort_by{|k,v| k }.each do |ncid, v| | |
if holdings[ncid] | |
bib = [:ncid, :trd_title, :trd_author, :ed, :publ, :pubdt, :year1, :physp, :physs, :trr ].map{|e| v[e] }.join("\t") | |
holdings[ncid].each do |holding| | |
puts [ bib, holding[:vol], holding[:cln], holding[:rgtn] ].join("\t") | |
end | |
else | |
puts [:ncid, :trd_title, :trd_author, :ed, :publ, :pubdt, :year1, :physp, :physs, :trr ].map{|e| v[e] }.join("\t") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment