Created
January 23, 2012 21:13
-
-
Save mark-cooper/1665565 to your computer and use it in GitHub Desktop.
Updating a field/subfield value with ruby-marc
This file contains hidden or 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 'marc' | |
TAG = '856' | |
SUB = 'y' | |
STR = 'Img100' | |
REP = 'Img200' | |
count = 0 | |
w = MARC::Writer.new('dla_fixed.mrc') | |
MARC::ForgivingReader.new('records/dla.mrc').each do |r| | |
if f = r.find { |f| f.tag == TAG and f[SUB] =~ /#{STR}/ } | |
f[SUB].gsub!(/#{STR}/, REP) | |
w.write r | |
count += 1 | |
end | |
end | |
w.close | |
puts count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment