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

#bibliographic_levelObject (readonly)

Returns the value of attribute bibliographic_level.



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

def bibliographic_level
  @bibliographic_level
end

#encoding_levelObject (readonly)

Returns the value of attribute encoding_level.



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

def encoding_level
  @encoding_level
end

#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

#record_typeObject (readonly)

Returns the value of attribute record_type.



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

def record_type
  @record_type
end

Instance Method Details

#DescObject



126
127
128
129
# File 'lib/enhanced_marc/leader.rb', line 126

def Desc
  self.get_desc unless @descriptive_cataloging_form
  return @descriptive_cataloging_form
end

#ELvlObject



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

def ELvl
  self.get_elvl unless @encoding_level
  return @encoding_level
end

#get_blvlObject



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

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

#get_blvl_codeObject



24
25
26
# File 'lib/enhanced_marc/leader.rb', line 24

def get_blvl_code
  return self[7,1]
end

#get_descObject



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

def get_desc
  codes = {' '=>'Non-ISBD', 'a'=>'AACR2', 'i'=>'ISBD', 'u'=>'Unknown'}
  return @descriptive_cataloging_form = codes[self.get_desc_code]      
end

#get_desc_codeObject



117
118
119
# File 'lib/enhanced_marc/leader.rb', line 117

def get_desc_code
  return self[18,1]
end

#get_elvlObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/enhanced_marc/leader.rb', line 92

def get_elvl
  elvls = {
    ' '=>'Full',
    '1'=>'Full, not examined',
    '2'=>'Less-than-full',
    '3'=>'Abbreviated',
    '4'=>'Core',
    '5'=>'Partial',
    '7'=>'Minimal',
    '8'=>'Prepublication',
    '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',
    'J'=>'Deleted record'
  }
  return @encoding_level = elvls[self.get_elvl_code]
end

#get_elvl_codeObject



88
89
90
# File 'lib/enhanced_marc/leader.rb', line 88

def get_elvl_code
  return self[17,1]
end

#get_typeObject



28
29
30
# File 'lib/enhanced_marc/leader.rb', line 28

def get_type
  return @record_type = self.type_translator(self.get_type_code, self.get_blvl_code)
end

#get_type_codeObject



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

def get_type_code
  return self[6,1]    
end

#is_archival?Boolean

Returns:

  • (Boolean)


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

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

#parse_leaderObject



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

def parse_leader
  self.get_type
  self.get_blvl
  self.get_elvl
end

#set_type(type) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/enhanced_marc/leader.rb', line 50

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

#type_translator(type_code, blvl_code) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/enhanced_marc/leader.rb', line 64

def type_translator(type_code, blvl_code)
  valid_types = ['a','t','g','k','r','o','p','e','f','c','d','i','j','m']
  unless valid_types.index(type_code)    
    raise ArgumentError, "Invalid Type!" 
    return
  end
  rec_types = {
    'BKS' => { :type => /[at]{1}/,	:blvl => /[acdm]{1}/ },
   'SER' => { :type => /[a]{1}/,	:blvl => /[bs]{1}/ },
    'VIS' => { :type => /[gkro]{1}/,	:blvl => /[abcdms]{1}/ },
    'MIX' => { :type => /[p]{1}/,	:blvl => /[cd]{1}/ },
    'MAP' => { :type => /[ef]{1}/,	:blvl => /[abcdms]{1}/ },
    'SCO' => { :type => /[cd]{1}/,	:blvl => /[abcdms]{1}/ },
    'REC' => { :type => /[ij]{1}/,	:blvl => /[abcdms]{1}/ },
    'COM' => { :type => /[m]{1}/,	:blvl => /[abcdms]{1}/ }
  } 
  
  rec_types.each_key { | type |
    return type if type_code.match(rec_types[type][:type]) and blvl_code.match(rec_types[type][:blvl])
  } 
  raise ArgumentError, "Invalid BLvl!"
  return nil
end