Class: MARC::Leader

Inherits:
String
  • Object
show all
Defined in:
lib/enhanced_marc/leader.rb

Overview

A class for accessing the MARC Leader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(leader) ⇒ Leader

Returns a new instance of Leader.



6
7
8
9
10
11
12
# File 'lib/enhanced_marc/leader.rb', line 6

def initialize(leader)
  super
  # leader defaults:
  # http://www.loc.gov/marc/bibliographic/ecbdldrd.html
  self[10..11] = '22'
  self[20..23] = '4500'
end

Instance Attribute Details

#fixed_fieldsObject (readonly)

Returns the value of attribute fixed_fields.



5
6
7
# File 'lib/enhanced_marc/leader.rb', line 5

def fixed_fields
  @fixed_fields
end

#leaderObject (readonly)

Returns the value of attribute leader.



5
6
7
# File 'lib/enhanced_marc/leader.rb', line 5

def leader
  @leader
end

Instance Method Details

#archival?Boolean Also known as: is_archival?

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/enhanced_marc/leader.rb', line 32

def archival?
  return true if self[8, 1] == 'a'
  false
end

#blvlObject Also known as: bibliographic_level, get_blvl



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/enhanced_marc/leader.rb', line 39

def blvl
  blvls = {
    'a' => 'Monographic component part',
    'b' => 'Serial component part',
    'c' => 'Collection',
    'd' => 'Subunit',
    'i' => 'Integrating resource',
    'm' => 'Monograph/Item',
    's' => 'Serial'
  }
  blvls[get_blvl_code]
end

#blvl_codeObject Also known as: get_blvl_code



20
21
22
# File 'lib/enhanced_marc/leader.rb', line 20

def blvl_code
  self[7, 1]
end

#descObject Also known as: descriptive_cataloging_form, Desc, get_desc



120
121
122
123
124
125
# File 'lib/enhanced_marc/leader.rb', line 120

def desc
  codes = {
    ' ' => 'Non-ISBD', 'a' => 'AACR2', 'i' => 'ISBD', 'u' => 'Unknown'
  }
  codes[get_desc_code]
end

#desc_codeObject Also known as: get_desc_code



114
115
116
# File 'lib/enhanced_marc/leader.rb', line 114

def desc_code
  self[18, 1]
end

#elvlObject Also known as: encoding_level, ELvl, get_elvl



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/enhanced_marc/leader.rb', line 98

def elvl
  elvls = { ' ' => 'Full', '1' => 'Full, not examined',
            '2' => 'Less-than-full', '3' => 'Abbreviated',
            '4' => 'Core', '5' => 'Partial', '7' => 'Minimal',
            '8' => 'Prepublication', 'J' => 'Deleted record',
            'I' => 'Full-level input by OCLC participants',
            'K' => 'Less-than-full input by OCLC participants',
            'L' => 'Full-level input added from a batch process',
            'M' => 'Less-than-full added from a batch process',
            'E' => 'System-identified MARC error in batchloaded record' }
  elvls[get_elvl_code]
end

#elvl_codeObject Also known as: get_elvl_code



93
94
95
# File 'lib/enhanced_marc/leader.rb', line 93

def elvl_code
  self[17, 1]
end

#record_typeObject Also known as: get_type



26
27
28
# File 'lib/enhanced_marc/leader.rb', line 26

def record_type
  type_translator(get_type_code, get_blvl_code)
end

#record_type=(type) ⇒ Object Also known as: set_type



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/enhanced_marc/leader.rb', line 55

def record_type=(type)
  if type.length == 1
    translated_type = types(type)
    raise ArgumentError, 'Invalid Type' if translated_type.nil?
  elsif type.length > 1
    type = types(type)
    raise ArgumentError, 'Invalid Type' if type.nil?
  else
    raise ArgumentError, 'Invalid Type'
  end
  self[6] = type
end

#type_codeObject Also known as: get_type_code



14
15
16
# File 'lib/enhanced_marc/leader.rb', line 14

def type_code
  self[6, 1]
end

#type_translator(type_code, blvl_code) ⇒ Object

Raises:

  • (ArgumentError)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/enhanced_marc/leader.rb', line 70

def type_translator(type_code, blvl_code)
  valid_types = %w[a t g k r o p e f c d i j m]
  raise ArgumentError, 'Invalid Type!' unless valid_types.index(type_code)

  rec_types = {
    'BKS' => { type: /[at]{1}/,	blvl: /[acdm]{1}/ },
    'SER' => { type: /[a]{1}/,	blvl: /[bis]{1}/ },
    'VIS' => { type: /[gkro]{1}/,	blvl: /[abcdims]{1}/ },
    'MIX' => { type: /[p]{1}/,	blvl: /[cd]{1}/ },
    'MAP' => { type: /[ef]{1}/,	blvl: /[abcdims]{1}/ },
    'SCO' => { type: /[cd]{1}/,	blvl: /[abcdims]{1}/ },
    'REC' => { type: /[ij]{1}/,	blvl: /[abcdims]{1}/ },
    'COM' => { type: /[m]{1}/,	blvl: /[abcdims]{1}/ }
  }

  rec_types.each_key do |type|
    if type_code.match(rec_types[type][:type]) && blvl_code.match(rec_types[type][:blvl])
      return type
    end
  end
  raise ArgumentError, 'Invalid BLvl!'
end