Class: OverdriveMetadata::ERecord

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

Direct Known Subclasses

EAudioBook, EBook

Constant Summary collapse

GMD =
'[electronic resource]'
DATE_ERR =
'Date information not present for fixed field'
FIXF_ERR =
'Invalid fixed field created'
TITL_ERR =
'Title data is missing for record'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeERecord

Returns a new instance of ERecord.



211
212
213
214
215
216
217
218
219
# File 'lib/overdrive_metadata.rb', line 211

def initialize
  @record = MARC::Record.new
  @ldr = record.leader
  @ldr[5]  = 'n'
  @ldr[7]  = 'm'
  @ldr[17] = 'M'
  @ldr[18] = 'a'
  fixed_field = ''
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



209
210
211
# File 'lib/overdrive_metadata.rb', line 209

def record
  @record
end

Instance Method Details

#make_control_field(tag, value) ⇒ Object



221
222
223
224
# File 'lib/overdrive_metadata.rb', line 221

def make_control_field(tag, value)
  return nil if value.empty?
  @record.append MARC::ControlField.new(tag, value)
end

#make_data_field(tag, ind1, ind2, subfields) ⇒ Object



226
227
228
229
230
231
232
233
# File 'lib/overdrive_metadata.rb', line 226

def make_data_field(tag, ind1, ind2, subfields)
  s = []
  subfields.each do |k,v|
    return nil if v.nil? or v.empty?
    s << MARC::Subfield.new(k, v)
  end
  @record.append MARC::DataField.new(tag, ind1, ind2, *s)
end

#make_fixed_field(year, month, day) ⇒ Object

Raises:



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/overdrive_metadata.rb', line 235

def make_fixed_field(year, month, day)
  raise DATE_ERR if year.empty?
  fixed_field = @fixed_field
  unless month.empty? and day.empty?
    month = '0' + month if month.length == 1
    day   = '0' + day if day.length == 1
    fixed_field[0..5] = year[2..3] + month + day
    fixed_field[7..10] = year
  else
    fixed_field[7..10] = year
  end
  raise FIXF_ERR unless fixed_field.length == 40
  make_control_field('008', fixed_field)
end

#make_publication(place, publisher, year) ⇒ Object



266
267
268
269
# File 'lib/overdrive_metadata.rb', line 266

def make_publication(place, publisher, year)
  return nil if place.empty? or publisher.empty? or year.empty?
  make_data_field('260', ' ', ' ', {'a' => "#{place} :", 'b' => "#{publisher},", 'c' => "#{year}."})
end

#make_title(title, sor) ⇒ Object

Raises:



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/overdrive_metadata.rb', line 250

def make_title(title, sor)
  raise TITL_ERR if title.empty?
    t_ind1  = sor.empty? ? '0' : '1'
    t_ind2  = non_filing_characters title
    subfields = {}
    subfields['a'] = title
    subfields['h'] = GMD + ' /'
    unless sor.empty?
      value = sor[-1] == '.' ? "by #{sor}" : "by #{sor}."
      subfields['c'] = value
    else
      subfields['h'].gsub!(/\s+\/$/, '.')
    end
    make_data_field('245', t_ind1, t_ind2, subfields)
end

#non_filing_characters(title) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/overdrive_metadata.rb', line 271

def non_filing_characters(title)
  return case
  when title.match(/^The /)
      '4'
  when title.match(/^An /)
      '3'
  when title.match(/^A /)
      '2'     
  else
      '0'
  end
end