4 attr_accessor :selected, :marc, :authorities, :rank
\r
6 def initialize(marc, zserver, selected = false)
\r
13 #def authorities<< (authority)
\r
17 full_string = "\n---------------RECORD----------------\nzserver: " + zserver.to_s + "\n" + marc.to_s + "---------------RECORD----------------\n"
\r
22 self.marc['245']['a']
\r
29 self.marc['260']['a']
\r
33 if self.marc['260'] && self.marc['260']['c']
\r
34 date = self.marc['260']['c'].dup
\r
49 end #save MARC record to file in proper format (MARC, MARCXML)
\r
53 # linter depends on Perl's MARC::Lint and hence Perl's MARC::Record
\r
54 # Use cpan to install them.
\r
57 xml_rec = (rec.to_xml).to_s
\r
59 puts 'You do not have the Perl MARC::Lint module installed or have disabled this feature.'
\r
62 contents = `perl "#{ROOT}"/linter.pl "#{xml_rec}"`
\r
64 puts "there were no errors detected by the linter."
\r
68 if rec.leader[18,1] == 'a'
\r
69 puts "Leader indicates: AACR"
\r
70 elsif rec.leader[18,1] == 'i'
\r
71 puts "Leader indicates: ISBD"
\r
73 puts "Leader indicates NOT AACR nor ISBD."
\r
77 #++ The local_script method is for automating changes to the record before saving it. See the main script to turn on this feature. See zoomer.yaml for instructions on creating a script for your purposes.
\r
78 def local_script(script)
\r
82 #--creating my procs for creating fields and appending subfields
\r
83 # these two should probably be moved to methods
\r
84 create_datafield = proc{|record, field, i1, i2| puts "Creating datafield: #{field}"; record.append(MARC::DataField.new(field.to_s, i1.to_s, i2.to_s)); puts "****", record, "***" if $testing;}
\r
86 append_subfield = proc{|record, field, subfield, val|
\r
88 subfield = subfield.to_s
\r
91 if value.include?('proc ')
\r
92 #I've had problems with this bit but it seems to work now
\r
93 value = value.sub(/^proc /, '')
\r
94 real_value = eval("#{$procs[value]}")
\r
95 next if real_value == nil
\r
96 record[field].append(MARC::Subfield.new(subfield, real_value))
\r
98 record[field].append(MARC::Subfield.new(subfield, value))
\r
102 script.each do |single_script|
\r
103 puts "--------------------------------------" if $testing
\r
104 puts single_script.join(', ') if $testing
\r
105 op, field, subfield, filler= single_script
\r
107 subfield = subfield.to_s
\r
109 if operation.include?('proc ')
\r
110 operation = operation.dup.sub(/^proc /, '')
\r
111 eval("#{$procs[operation]}")
\r
112 elsif operation == 'create-field'
\r
113 create_datafield.call(record, field, subfield, filler)
\r
114 elsif operation == 'append-subfield'
\r
115 append_subfield.call(record, field, subfield, filler)
\r
116 elsif operation == 'prompt'
\r
117 field_data = ask("What do you want to go into the #{field}#{subfield} #{filler}? ")
\r
119 next if field_data.empty?
\r
120 m_fields = record.find_all{|x| x.tag == field}
\r
122 puts "m_fields is empty!!"
\r
123 create_datafield.call(record, field, ' ', ' ')
\r
124 m_fields = record.find_all{|x| x.tag == field}
\r
126 m_fields.each {|field| field.append(MARC::Subfield.new(subfield, field_data))}
\r
127 elsif operation == 'remove'
\r
128 to_remove = record.find_all {|f| f.tag =~ Regexp.new( field.gsub('X','.'))}
\r
129 to_remove.each do |remove|
\r
130 record.fields.delete(remove)
\r
132 elsif operation == 'sort-tags' ##This doesn't work right now
\r
133 puts "sorting by tag"
\r
134 puts record , "################"
\r
135 record = record.sort_by{| field | field.tag}
\r
139 puts "there's nothing for that yet in local_script"
\r
141 puts record if $testing
\r
150 puts "Subfield Editing"
\r
151 puts "To denote which subfield you want to edit put it in the form of 245a.\nIn the case of repeating fields or subfields you will be prompted\nto choose the one you wish to edit. "
\r
154 fs = ask("What field and subfield would you like to edit (in form 245a) or quit?\n> "){|q| q.readline = true}
\r
155 if fs == 'q' || fs == 'quit'
\r
159 if !(fs =~/\d\d\d\w/ )
\r
160 puts "That's not a valid value"
\r
163 self.change_subfield(fs)
\r
167 #edit_subfield is passed to a MARC::Record object and give a subfield
\r
168 def change_subfield(fs)
\r
169 field_subfield = subfield_parse(fs)
\r
170 field = field_subfield[0]
\r
171 subfield = field_subfield[1]
\r
173 fields = self.marc.find_all {|f| f.tag == field}
\r
175 for field in fields
\r
176 subfields << field.find_all {|s| s.code == subfield}
\r
179 if subfields.length > 1
\r
181 for subfield in subfields
\r
182 puts "#{i}\t#{subfield}"
\r
185 num_to_change = ask("Which subfield do you want to change?"){|q| q.readline = true}
\r
186 subfield_to_change = subfields[num_to_change.to_i]
\r
187 elsif subfields.length == 1
\r
188 subfield_to_change = subfields[0]
\r
189 elsif subfields.empty?
\r
190 puts "No such subfield!"
\r
195 puts self.marc; puts
\r
197 print "Currently:\t"
\r
198 puts subfield_to_change.value
\r
199 edit = ask("Your edit:\t"){|q| q.readline = true}
\r
200 subfield_to_change.value = edit
\r
201 puts; puts self.marc; puts
\r
205 #subfield_parse method for getting from '245a' to ['245','a']
\r
206 def subfield_parse(combined)
\r
207 field_subfield = []
\r
208 field_subfield << combined[0, 3]
\r
209 field_subfield << combined[3,1]
\r
214 orig_marc = Tempfile.new("orig_marc-")
\r
215 orig_marc << self.marc.to_marc
\r
218 line_format = `yaz-marcdump #{orig_marc.path}`
\r
220 out = Tempfile.new("full_edit-")
\r
224 system("#{TEXT_EDITOR} #{out.path}")
\r
226 final = Tempfile.new("final-")
\r
228 `yaz-marcdump -i line -o marc #{out.path} > #{final.path}`
\r
230 record = MARC::Reader.new(final.path)
\r
236 puts self.marc.inspect
\r
241 # To use marc_to_csv it must be passed a csv template in the order of the fields.
\r
242 # See the zoomer.yaml file for instructions on creating a template.
\r
243 # See the main script for turning this feature on.
\r
244 def marc_to_csv(template)
\r
246 template.each do |template|
\r
247 field, subfield, leng = template
\r
249 subfield = subfield.to_s
\r
250 if field == 'prompt'
\r
251 value = ask("prompt: please enter the #{field} #{subfield}") #--subfield here is a label for the prompt
\r
253 value = "\"#{value}\","
\r
255 elsif field.length == 3 and field.match('\d')
\r
256 fields = self.marc.find_all { | f | f.tag =~ Regexp.new( field.gsub('X','.'))}
\r
260 value = blank_field_prompt(field, subfield)
\r
261 #eval(blank_field_prompt)
\r
265 value += f[subfield] + "|"
\r
267 value = blank_field_prompt(field, subfield)
\r
271 value.sub!(/\|$/, '')
\r
272 value = value[0, leng] if leng
\r
273 #puts "value: #{value}"
\r
274 value = "\"#{value}\","
\r
278 puts "this is not a valid value for marc_to_csv"
\r
282 values[-1].sub!(/\,$/, '')
\r
283 values = values.to_s
\r