Last active
March 27, 2024 13:14
-
-
Save Beck-Davis/db08731ee27d76197378c91503b2fffc to your computer and use it in GitHub Desktop.
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
require_relative './../lib/marc_cleanup' | |
def duplicate_fields?(record) #creates an array with each unique field value converted to a string | |
field_array = [] | |
record.fields.each do |field| | |
return true if field_array.include?(field.to_s) | |
field_array << field.to_s | |
end | |
false | |
end | |
writer = MARC::XMLWriter.new('filepath') | |
Dir.glob('filepath').each do |file| | |
puts File.basename(file) | |
reader = MARC::XMLReader.new(file, parser: 'magic', ignore_namespace: true) | |
reader.each do |record| | |
if duplicate_fields?(record) | |
writer.write(record) | |
end | |
end | |
end | |
writer.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment