Sha256: fb5dbf62d466aa0274bcc6c98a48b317e14eccf14be3f1b46c4e57fd02a66067

Contents?: true

Size: 1.4 KB

Versions: 11

Compression:

Stored size: 1.4 KB

Contents

# given a record, find the bib_format code
class Traject::UMichFormat::BibFormat

  attr_reader :code

  # Determine the bib format code
  #
  # @param [MARC::Record] record The record to test

  def initialize(record)
    ldr = record.leader

    type = ldr[6]
    lev  = ldr[7]
    @code = self.determine_bib_code(type, lev)
  end

  def determine_bib_code(type, lev)
    return 'BK' if bibformat_bk(type, lev)
    return "CF" if bibformat_cf(type, lev)
    return "VM" if bibformat_vm(type, lev)
    return "MU" if bibformat_mu(type, lev)
    return "MP" if bibformat_mp(type, lev)
    return "SE" if bibformat_se(type, lev)
    return "MX" if bibformat_mx(type, lev)

    # Extra check for serial
    return "SE" if lev == 's'

    # No match
    return 'XX'

  end

  def bibformat_bk(type, lev)
    %w[a t].include?(type) && %w[a c d m].include?(lev)
  end

  def bibformat_cf(type, lev)
    (type == 'm') && %w[a b c d m s].include?(lev)
  end

  def bibformat_vm(type, lev)
    %w[g k o r].include?(type) && %w[a b c d m s].include?(lev)
  end

  def bibformat_mu(type, lev)
    %w[c d i j].include?(type) && %w[a b c d m s].include?(lev)
  end

  def bibformat_mp(type, lev)
    %w[e f].include?(type) && %w[a b c d m s].include?(lev)
  end

  def bibformat_se(type, lev)
    (type == 'a') && %w[b s i].include?(lev)
  end

  def bibformat_mx(type, lev)
    %w[b p].include?(type) && %w[a b c d m s].include?(lev)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
traject_umich_format-0.4.3 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.4.2 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.4.1 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.4.0 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.3.0 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.2.0 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.1.4 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.1.3 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.1.2 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.1.1 lib/traject/umich_format/bib_format.rb
traject_umich_format-0.1.0 lib/traject/umich_format/bib_format.rb