Class: ZCC::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/zcc/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(marc, zserver, selected = false) ⇒ Record

Returns a new instance of Record.



6
7
8
9
10
11
# File 'lib/zcc/record.rb', line 6

def initialize(marc, zserver, selected = false)
  @marc = marc
  @zserver = zserver
  @selected = selected
  @rank = 0
end

Instance Attribute Details

#authoritiesObject

Returns the value of attribute authorities.



4
5
6
# File 'lib/zcc/record.rb', line 4

def authorities
  @authorities
end

#marcObject

Returns the value of attribute marc.



4
5
6
# File 'lib/zcc/record.rb', line 4

def marc
  @marc
end

#rankObject

Returns the value of attribute rank.



4
5
6
# File 'lib/zcc/record.rb', line 4

def rank
  @rank
end

#selectedObject

Returns the value of attribute selected.



4
5
6
# File 'lib/zcc/record.rb', line 4

def selected
  @selected
end

#zserverObject (readonly)

Returns the value of attribute zserver.



5
6
7
# File 'lib/zcc/record.rb', line 5

def zserver
  @zserver
end

Instance Method Details

#authorObject



25
26
# File 'lib/zcc/record.rb', line 25

def author 
end

#change_subfield(fs) ⇒ Object

edit_subfield is passed to a MARC::Record object and give a subfield



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/zcc/record.rb', line 168

def change_subfield(fs)
  field_subfield = subfield_parse(fs)
  field = field_subfield[0]
  subfield = field_subfield[1]

  fields = self.marc.find_all {|f| f.tag == field}
  subfields = []
  for field in fields
   subfields << field.find_all {|s| s.code == subfield}
  end
  subfields.flatten!
  if subfields.length > 1
    i = 0
    for subfield in subfields
     puts "#{i}\t#{subfield}"
      i += 1
    end
   num_to_change = ask("Which subfield do you want to change?"){|q| q.readline = true}
   subfield_to_change = subfields[num_to_change.to_i]
  elsif subfields.length == 1
    subfield_to_change = subfields[0]
  elsif subfields.empty?
    puts "No such subfield!"
   return nil
  end
  

  puts self.marc; puts

  print "Currently:\t"
  puts subfield_to_change.value 
  edit = ask("Your edit:\t"){|q| q.readline = true}
  subfield_to_change.value = edit
  puts; puts self.marc; puts

end

#editObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/zcc/record.rb', line 149

def edit
  puts "Subfield Editing"
  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. "
  continue = true
  while continue
   fs = ask("What field and subfield would you like to edit (in form 245a) or quit?\n>   "){|q| q.readline = true}
    if fs == 'q' || fs == 'quit'
      continue = false
    next
    end
    if !(fs =~/\d\d\d\w/ )
      puts "That's not a valid value"
      next
    end
    self.change_subfield(fs)
  end
end

#extentObject

1XX?



28
29
30
# File 'lib/zcc/record.rb', line 28

def extent 
  self.marc['260']['a']
end

#full_editObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/zcc/record.rb', line 212

def full_edit
  #puts self.class
  orig_marc = Tempfile.new("orig_marc-")
  orig_marc << self.marc.to_marc
  orig_marc.close
  
  line_format = `yaz-marcdump #{orig_marc.path}`
  
  out = Tempfile.new("full_edit-")
  out << line_format
  out.close
  
  system("#{TEXT_EDITOR} #{out.path}")

  final = Tempfile.new("final-")
  final.close
  `yaz-marcdump -i line -o marc #{out.path} > #{final.path}`
  
  record = MARC::Reader.new(final.path)
  for rec in record
    puts rec
    self.marc = rec
    puts rec.class
  end
  puts self.marc.inspect
  
end

#linterObject

linter depends on Perl’s MARC::Lint and hence Perl’s MARC::Record Use cpan to install them.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/zcc/record.rb', line 55

def linter
  rec = self.marc
  xml_rec = (rec.to_xml).to_s
  if LINTER == false
    puts 'You do not have the Perl MARC::Lint module installed or have disabled this feature.'
    return
  end
  contents = `perl "#{ROOT}"/linter.pl "#{xml_rec}"`
  if contents.empty?
    puts "there were no errors detected by the linter."
  else
    puts contents	
  end
  if rec.leader[18,1] == 'a'
    puts "Leader indicates: AACR"
  elsif rec.leader[18,1] == 'i'
    puts "Leader indicates: ISBD"
  else
    puts "Leader indicates NOT AACR nor ISBD."
  end
end

#local_script(script) ⇒ Object

++ 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.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/zcc/record.rb', line 78

def local_script(script)
  #print $clear_code
  record = self.marc

  #--creating my procs for creating fields and appending subfields
  # these two should probably be moved to methods
  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;}

  append_subfield = proc{|record, field, subfield, val| 
    field = field.to_s
    subfield = subfield.to_s
    value = val.dup
    value = value.to_s
    if value.include?('proc ')
      #I've had problems with this bit but it seems to work now
      value = value.sub(/^proc /, '')
      real_value = eval("#{$procs[value]}") 
      next if real_value == nil                
      record[field].append(MARC::Subfield.new(subfield, real_value))
    elsif
      record[field].append(MARC::Subfield.new(subfield, value))
    end
  }

  script.each do |single_script|
    puts "--------------------------------------" if $testing
    puts single_script.join(', ') if $testing
    op, field, subfield, filler= single_script
    field = field.to_s
    subfield = subfield.to_s
    operation = op.dup
    if operation.include?('proc ')
      operation = operation.dup.sub(/^proc /, '')
      eval("#{$procs[operation]}")
    elsif operation == 'create-field'
      create_datafield.call(record, field, subfield, filler)
    elsif operation == 'append-subfield'
      append_subfield.call(record, field, subfield, filler)
    elsif operation == 'prompt'
      field_data = ask("What do you want to go into the #{field}#{subfield} #{filler}? ")
      
      next if field_data.empty?
      m_fields = record.find_all{|x| x.tag == field}
      if m_fields.empty?
        puts "m_fields is empty!!"
        create_datafield.call(record, field, ' ', ' ')
        m_fields = record.find_all{|x| x.tag == field}
      end
      m_fields.each {|field| field.append(MARC::Subfield.new(subfield, field_data))}
    elsif operation == 'remove'
      to_remove = record.find_all {|f|  f.tag =~ Regexp.new( field.gsub('X','.'))}
      to_remove.each do |remove|
        record.fields.delete(remove)
      end
    elsif operation == 'sort-tags' ##This doesn't work right now
      puts "sorting by tag"
      puts record , "################"
      record = record.sort_by{| field | field.tag}
      puts record
      STDIN.gets
    else
      puts "there's nothing for that yet in local_script"
    end
    puts record if $testing
  end

  record
end

#marc_to_csv(template) ⇒ Object

See the zoomer.yaml file for instructions on creating a template. See the main script for turning this feature on.



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/zcc/record.rb', line 244

def marc_to_csv(template)
  values = []
  template.each do |template|
    field, subfield, leng = template
    field = field.to_s
    subfield = subfield.to_s
    if field == 'prompt'
      value = ask("prompt: please enter the #{field} #{subfield}") #--subfield here is a label for the prompt
      
      value = "\"#{value}\","
      values << value
    elsif field.length == 3 and field.match('\d')
      fields = self.marc.find_all { | f |  f.tag =~ Regexp.new( field.gsub('X','.'))}
      value = ''
      if fields.empty?
        #puts "oh, no!"
        value = blank_field_prompt(field, subfield)
        #eval(blank_field_prompt)
      else
        fields.each do |f|
          if f[subfield]
            value += f[subfield] + "|"
          else
            value = blank_field_prompt(field, subfield)
          end
        end
      end
      value.sub!(/\|$/, '')
      if leng
          if value.length == value.jlength
            value = value[0, leng]
          else
            puts "This value seems to have multibyte characters. If a byte gets dropped off the end that spells trouble."
            leng = ask("How many bytes would you like to take?")
            value = value[0, leng.to_s]
          end
        end
      #puts "value: #{value}"
      value = "\"#{value}\","
      values << value

    else
      puts "this is not a valid value for marc_to_csv"
    end
  end
  #puts values
  values[-1].sub!(/\,$/, '')
  values = values.to_s
  values += "\n"
end

#save(format) ⇒ Object



48
49
# File 'lib/zcc/record.rb', line 48

def save(format)
end

#subfield_parse(combined) ⇒ Object

subfield_parse method for getting from ‘245a’ to [‘245’,‘a’]



206
207
208
209
210
# File 'lib/zcc/record.rb', line 206

def subfield_parse(combined)
  field_subfield = []
  field_subfield << combined[0, 3]
  field_subfield << combined[3,1]
end

#titleObject



21
22
23
# File 'lib/zcc/record.rb', line 21

def title 
  self.marc['245']['a']
end

#to_sObject

def authorities<< (authority) end



16
17
18
19
# File 'lib/zcc/record.rb', line 16

def to_s
  full_string = "\n---------------RECORD----------------\nzserver: " + zserver.to_s + "\n" +  marc.to_s +  "---------------RECORD----------------\n"
  full_string
end

#year_260Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zcc/record.rb', line 32

def year_260
  if self.marc['260'] && self.marc['260']['c']
    date = self.marc['260']['c'].dup
    date.gsub!('[', '')
    date.gsub!(']', '')
    date.gsub!('c','')
    date
  else
    date = '0'
    date
  end
end

#years_fixedObject



45
46
# File 'lib/zcc/record.rb', line 45

def years_fixed 
end