Skip to content

Instantly share code, notes, and snippets.

@Beck-Davis
Last active March 27, 2024 13:14
Show Gist options
  • Save Beck-Davis/db08731ee27d76197378c91503b2fffc to your computer and use it in GitHub Desktop.
Save Beck-Davis/db08731ee27d76197378c91503b2fffc to your computer and use it in GitHub Desktop.
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