4 attr_accessor :selected, :marc, :authorities
\r
6 def initialize(marc, zserver, selected = false)
\r
12 #def authorities<< (authority)
\r
16 full_string = "\n---------------RECORD----------------\nzserver: " + zserver.to_s + "\n" + marc.to_s + "---------------RECORD----------------\n"
\r
21 self.marc['245']['a']
\r
28 self.marc['260']['a']
\r
32 date = self.marc['260']['c'].dup
\r
43 end #save MARC record to file in proper format (MARC, MARCXML)
\r
47 # linter depends on Perl's MARC::Lint and hence Perl's MARC::Record
\r
48 # Use cpan to install them.
\r
51 xml_rec = (rec.to_xml).to_s
\r
53 puts 'You do not have the Perl MARC::Lint module installed or have disabled this feature.'
\r
56 contents = `perl "#{File.expand_path("~")}"/.zcc/linter.pl "#{xml_rec}"`
\r
58 puts "there were no errors detected by the linter."
\r
62 if rec.leader[18,1] == 'a'
\r
63 puts "Leader indicates: AACR"
\r
64 elsif rec.leader[18,1] == 'i'
\r
65 puts "Leader indicates: ISBD"
\r
67 puts "Leader indicates NOT AACR nor ISBD."
\r
71 #++ 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
72 def local_script(script)
\r
76 #--creating my procs for creating fields and appending subfields
\r
77 # these two should probably be moved to methods
\r
78 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
80 append_subfield = proc{|record, field, subfield, val|
\r
82 subfield = subfield.to_s
\r
85 if value.include?('proc ')
\r
86 #I've had problems with this bit but it seems to work now
\r
87 value = value.sub(/^proc /, '')
\r
88 real_value = eval("#{$procs[value]}")
\r
89 next if real_value == nil
\r
90 record[field].append(MARC::Subfield.new(subfield, real_value))
\r
92 record[field].append(MARC::Subfield.new(subfield, value))
\r
96 script.each do |single_script|
\r
97 puts "--------------------------------------" if $testing
\r
98 puts single_script.join(', ') if $testing
\r
99 op, field, subfield, filler= single_script
\r
101 subfield = subfield.to_s
\r
103 if operation.include?('proc ')
\r
104 operation = operation.dup.sub(/^proc /, '')
\r
105 eval("#{$procs[operation]}")
\r
106 elsif operation == 'create-field'
\r
107 create_datafield.call(record, field, subfield, filler)
\r
108 elsif operation == 'append-subfield'
\r
109 append_subfield.call(record, field, subfield, filler)
\r
110 elsif operation == 'prompt'
\r
111 field_data = ask("What do you want to go into the #{field}#{subfield} #{filler}? ")
\r
113 next if field_data.empty?
\r
114 m_fields = record.find_all{|x| x.tag == field}
\r
116 puts "m_fields is empty!!"
\r
117 create_datafield.call(record, field, ' ', ' ')
\r
118 m_fields = record.find_all{|x| x.tag == field}
\r
120 m_fields.each {|field| field.append(MARC::Subfield.new(subfield, field_data))}
\r
121 elsif operation == 'remove'
\r
122 to_remove = record.find_all {|f| f.tag =~ Regexp.new( field.gsub('X','.'))}
\r
123 to_remove.each do |remove|
\r
124 record.fields.delete(remove)
\r
126 elsif operation == 'sort-tags' ##This doesn't work right now
\r
127 puts "sorting by tag"
\r
128 puts record , "################"
\r
129 record = record.sort_by{| field | field.tag}
\r
133 puts "there's nothing for that yet in local_script"
\r
135 puts record if $testing
\r
144 puts "Subfield Editing"
\r
145 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
148 fs = ask("What field and subfield would you like to edit (in form 245a) or quit?\n> "){|q| q.readline = true}
\r
149 if fs == 'q' || fs == 'quit'
\r
153 if !(fs =~/\d\d\d\w/ )
\r
154 puts "That's not a valid value"
\r
157 self.change_subfield(fs)
\r
161 #edit_subfield is passed to a MARC::Record object and give a subfield
\r
162 def change_subfield(fs)
\r
163 field_subfield = subfield_parse(fs)
\r
164 field = field_subfield[0]
\r
165 subfield = field_subfield[1]
\r
167 fields = self.marc.find_all {|f| f.tag == field}
\r
169 for field in fields
\r
170 subfields << field.find_all {|s| s.code == subfield}
\r
173 if subfields.length > 1
\r
175 for subfield in subfields
\r
176 puts "#{i}\t#{subfield}"
\r
179 num_to_change = ask("Which subfield do you want to change?"){|q| q.readline = true}
\r
180 subfield_to_change = subfields[num_to_change.to_i]
\r
181 elsif subfields.length == 1
\r
182 subfield_to_change = subfields[0]
\r
183 elsif subfields.empty?
\r
184 puts "No such subfield!"
\r
189 puts self.marc; puts
\r
191 print "Currently:\t"
\r
192 puts subfield_to_change.value
\r
193 edit = ask("Your edit:\t"){|q| q.readline = true}
\r
194 subfield_to_change.value = edit
\r
195 puts; puts self.marc; puts
\r
199 #subfield_parse method for getting from '245a' to ['245','a']
\r
200 def subfield_parse(combined)
\r
201 field_subfield = []
\r
202 field_subfield << combined[0, 3]
\r
203 field_subfield << combined[3,1]
\r
208 # To use marc_to_csv it must be passed a csv template in the order of the fields.
\r
209 # See the zoomer.yaml file for instructions on creating a template.
\r
210 # See the main script for turning this feature on.
\r
211 def marc_to_csv(template)
\r
213 template.each do |template|
\r
214 field, subfield, leng = template
\r
216 subfield = subfield.to_s
\r
217 if field == 'prompt'
\r
218 value = ask("prompt: please enter the #{field} #{subfield}") #--subfield here is a label for the prompt
\r
220 value = "\"#{value}\","
\r
222 elsif field.length == 3 and field.match('\d')
\r
223 fields = self.marc.find_all { | f | f.tag =~ Regexp.new( field.gsub('X','.'))}
\r
227 value = blank_field_prompt(field, subfield)
\r
228 #eval(blank_field_prompt)
\r
232 value += f[subfield] + "|"
\r
234 value = blank_field_prompt(field, subfield)
\r
238 value.sub!(/\|$/, '')
\r
239 value = value[0, leng] if leng
\r
240 #puts "value: #{value}"
\r
241 value = "\"#{value}\","
\r
245 puts "this is not a valid value for marc_to_csv"
\r
249 values[-1].sub!(/\,$/, '')
\r
250 values = values.to_s
\r