enhanced_marc 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +1 -0
- data/LICENSE +21 -0
- data/README +51 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/enhanced_marc-0.1.gem +0 -0
- data/enhanced_marc.gemspec +85 -0
- data/lib/enhanced_marc.rb +23 -0
- data/lib/enhanced_marc/book_record.rb +37 -0
- data/lib/enhanced_marc/book_type.rb +87 -0
- data/lib/enhanced_marc/computer_record.rb +37 -0
- data/lib/enhanced_marc/computer_type.rb +14 -0
- data/lib/enhanced_marc/leader.rb +132 -0
- data/lib/enhanced_marc/leftovers.rb +122 -0
- data/lib/enhanced_marc/map_record.rb +38 -0
- data/lib/enhanced_marc/map_type.rb +99 -0
- data/lib/enhanced_marc/mixed_record.rb +37 -0
- data/lib/enhanced_marc/mixed_type.rb +4 -0
- data/lib/enhanced_marc/reader.rb +105 -0
- data/lib/enhanced_marc/record.rb +96 -0
- data/lib/enhanced_marc/record_type.rb +310 -0
- data/lib/enhanced_marc/score_record.rb +38 -0
- data/lib/enhanced_marc/score_type.rb +4 -0
- data/lib/enhanced_marc/serial_record.rb +37 -0
- data/lib/enhanced_marc/serial_type.rb +87 -0
- data/lib/enhanced_marc/sound_record.rb +37 -0
- data/lib/enhanced_marc/sound_type.rb +4 -0
- data/lib/enhanced_marc/visual_record.rb +37 -0
- data/lib/enhanced_marc/visual_type.rb +38 -0
- data/lib/enhanced_marc/xmlreader.rb +58 -0
- data/pkg/enhanced_marc-0.1.gem +0 -0
- data/pkg/enhanced_marc-0.1.tgz +0 -0
- data/pkg/enhanced_marc-0.1.zip +0 -0
- data/pkg/enhanced_marc-0.1/Changes +1 -0
- data/pkg/enhanced_marc-0.1/LICENSE +21 -0
- data/pkg/enhanced_marc-0.1/README +51 -0
- data/pkg/enhanced_marc-0.1/Rakefile +41 -0
- data/pkg/enhanced_marc-0.1/test/ts_enhanced_marc.rb +5 -0
- data/test/ts_enhanced_marc.rb +5 -0
- metadata +113 -0
data/Changes
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2009-08-07: Refactored to monkeypatch ruby-marc rather than replace it.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2007 Ross Singer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Enhanced MARC is a set of classes, modules and methods that sit on top of ruby-marc (http://rubyforge.org/projects/marc) to help parse the contents of MARC records more easily and conveniently.
|
2
|
+
Installation:
|
3
|
+
gem sources -a http://gems.github.com
|
4
|
+
sudo gem install rsinger-enhanced_marc
|
5
|
+
|
6
|
+
Usage:
|
7
|
+
|
8
|
+
require 'enhanced_marc'
|
9
|
+
|
10
|
+
reader = MARC::Reader.new('marc.dat')
|
11
|
+
|
12
|
+
records = []
|
13
|
+
|
14
|
+
reader.each do | record |
|
15
|
+
records << record
|
16
|
+
end
|
17
|
+
|
18
|
+
>> records[0].class
|
19
|
+
=> MARC::BookRecord
|
20
|
+
|
21
|
+
>> records[0].is_conference?
|
22
|
+
=> false
|
23
|
+
|
24
|
+
>> records[0].is_manuscript?
|
25
|
+
=> false
|
26
|
+
|
27
|
+
# Send a boolean true if you want human readable forms, rather than MARC codes.
|
28
|
+
>> records[0].literary_form(true)
|
29
|
+
=> "Non-fiction"
|
30
|
+
|
31
|
+
>> records[0].nature_of_contents(true)
|
32
|
+
=> ["Bibliography", "Catalog"]
|
33
|
+
|
34
|
+
>> records[1].class
|
35
|
+
=> MARC::SoundRecord
|
36
|
+
|
37
|
+
>> records[1].composition_form(true)
|
38
|
+
=> "Jazz"
|
39
|
+
|
40
|
+
>> records[2].class
|
41
|
+
=> MARC::MapRecord
|
42
|
+
|
43
|
+
>> records[2].projection(true)
|
44
|
+
=> ["Cylindrical", "Mercator"]
|
45
|
+
|
46
|
+
>> records[2].relief(true)
|
47
|
+
=> ["Color"]
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
RUBY_ENHANCED_MARC_VERSION = '0.1'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
require 'rake/packagetask'
|
8
|
+
require 'rake/gempackagetask'
|
9
|
+
|
10
|
+
task :default => [:test]
|
11
|
+
|
12
|
+
Rake::TestTask.new('test') do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.pattern = 'test/tc_*.rb'
|
15
|
+
t.verbose = true
|
16
|
+
t.ruby_opts = ['-r marc', '-r test/unit']
|
17
|
+
end
|
18
|
+
|
19
|
+
Rake::RDocTask.new('doc') do |rd|
|
20
|
+
rd.rdoc_files.include("enhanced_marc/**/*.rb")
|
21
|
+
rd.main = 'MARC::Record'
|
22
|
+
rd.rdoc_dir = 'doc'
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'jeweler'
|
27
|
+
Jeweler::Tasks.new do |s|
|
28
|
+
|
29
|
+
s.add_dependency('marc')
|
30
|
+
s.add_dependency('locale')
|
31
|
+
s.name = 'enhanced_marc'
|
32
|
+
s.author = 'Ross Singer'
|
33
|
+
s.email = 'rossfsinger@gmail.com'
|
34
|
+
s.homepage = 'http://github.com/rsinger/enhanced-marc/tree'
|
35
|
+
s.summary = 'A DSL for MARC data'
|
36
|
+
s.description = 'A set of enhancements to ruby-marc to make parsing MARC data easier'
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
40
|
+
end
|
41
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.5
|
Binary file
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{enhanced_marc}
|
8
|
+
s.version = "0.1.5"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ross Singer"]
|
12
|
+
s.date = %q{2009-11-06}
|
13
|
+
s.description = %q{A set of enhancements to ruby-marc to make parsing MARC data easier}
|
14
|
+
s.email = %q{rossfsinger@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Changes",
|
21
|
+
"LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"enhanced_marc-0.1.gem",
|
26
|
+
"enhanced_marc.gemspec",
|
27
|
+
"lib/enhanced_marc.rb",
|
28
|
+
"lib/enhanced_marc/book_record.rb",
|
29
|
+
"lib/enhanced_marc/book_type.rb",
|
30
|
+
"lib/enhanced_marc/computer_record.rb",
|
31
|
+
"lib/enhanced_marc/computer_type.rb",
|
32
|
+
"lib/enhanced_marc/leader.rb",
|
33
|
+
"lib/enhanced_marc/leftovers.rb",
|
34
|
+
"lib/enhanced_marc/map_record.rb",
|
35
|
+
"lib/enhanced_marc/map_type.rb",
|
36
|
+
"lib/enhanced_marc/mixed_record.rb",
|
37
|
+
"lib/enhanced_marc/mixed_type.rb",
|
38
|
+
"lib/enhanced_marc/reader.rb",
|
39
|
+
"lib/enhanced_marc/record.rb",
|
40
|
+
"lib/enhanced_marc/record_type.rb",
|
41
|
+
"lib/enhanced_marc/score_record.rb",
|
42
|
+
"lib/enhanced_marc/score_type.rb",
|
43
|
+
"lib/enhanced_marc/serial_record.rb",
|
44
|
+
"lib/enhanced_marc/serial_type.rb",
|
45
|
+
"lib/enhanced_marc/sound_record.rb",
|
46
|
+
"lib/enhanced_marc/sound_type.rb",
|
47
|
+
"lib/enhanced_marc/visual_record.rb",
|
48
|
+
"lib/enhanced_marc/visual_type.rb",
|
49
|
+
"lib/enhanced_marc/xmlreader.rb",
|
50
|
+
"pkg/enhanced_marc-0.1.gem",
|
51
|
+
"pkg/enhanced_marc-0.1.tgz",
|
52
|
+
"pkg/enhanced_marc-0.1.zip",
|
53
|
+
"pkg/enhanced_marc-0.1/Changes",
|
54
|
+
"pkg/enhanced_marc-0.1/LICENSE",
|
55
|
+
"pkg/enhanced_marc-0.1/README",
|
56
|
+
"pkg/enhanced_marc-0.1/Rakefile",
|
57
|
+
"pkg/enhanced_marc-0.1/test/ts_enhanced_marc.rb",
|
58
|
+
"test/ts_enhanced_marc.rb"
|
59
|
+
]
|
60
|
+
s.homepage = %q{http://github.com/rsinger/enhanced-marc/tree}
|
61
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
62
|
+
s.require_paths = ["lib"]
|
63
|
+
s.rubygems_version = %q{1.3.5}
|
64
|
+
s.summary = %q{A DSL for MARC data}
|
65
|
+
s.test_files = [
|
66
|
+
"test/ts_enhanced_marc.rb"
|
67
|
+
]
|
68
|
+
|
69
|
+
if s.respond_to? :specification_version then
|
70
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
|
+
s.specification_version = 3
|
72
|
+
|
73
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
74
|
+
s.add_runtime_dependency(%q<marc>, [">= 0"])
|
75
|
+
s.add_runtime_dependency(%q<locale>, [">= 0"])
|
76
|
+
else
|
77
|
+
s.add_dependency(%q<marc>, [">= 0"])
|
78
|
+
s.add_dependency(%q<locale>, [">= 0"])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
s.add_dependency(%q<marc>, [">= 0"])
|
82
|
+
s.add_dependency(%q<locale>, [">= 0"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'marc'
|
2
|
+
require 'locale/info'
|
3
|
+
require 'enhanced_marc/reader'
|
4
|
+
require 'enhanced_marc/record'
|
5
|
+
require 'enhanced_marc/xmlreader'
|
6
|
+
require 'enhanced_marc/leader'
|
7
|
+
require 'enhanced_marc/book_record'
|
8
|
+
require 'enhanced_marc/serial_record'
|
9
|
+
require 'enhanced_marc/visual_record'
|
10
|
+
require 'enhanced_marc/mixed_record'
|
11
|
+
require 'enhanced_marc/map_record'
|
12
|
+
require 'enhanced_marc/score_record'
|
13
|
+
require 'enhanced_marc/sound_record'
|
14
|
+
require 'enhanced_marc/computer_record'
|
15
|
+
require 'enhanced_marc/record_type'
|
16
|
+
require 'enhanced_marc/book_type'
|
17
|
+
require 'enhanced_marc/computer_type'
|
18
|
+
require 'enhanced_marc/map_type'
|
19
|
+
require 'enhanced_marc/mixed_type'
|
20
|
+
require 'enhanced_marc/score_type'
|
21
|
+
require 'enhanced_marc/serial_type'
|
22
|
+
require 'enhanced_marc/sound_type'
|
23
|
+
require 'enhanced_marc/visual_type'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MARC
|
2
|
+
|
3
|
+
# A class that represents an individual MARC record. Every record
|
4
|
+
# is made up of a collection of MARC::Field objects.
|
5
|
+
|
6
|
+
class BookRecord < Record
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@leader[6] = 'a' if @leader[6,1] == ' '
|
11
|
+
@leader[7] = 'm' if @leader[7,1] == ' '
|
12
|
+
@record_type = 'BKS'
|
13
|
+
@bibliographic_level = @leader.get_blvl
|
14
|
+
self.extend BookType
|
15
|
+
self.inspect_fixed_fields
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_valid_type?
|
19
|
+
return false unless @leader[6,1].match(/[at]{1}/)
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
def is_valid_blvl?
|
23
|
+
return false unless @leader[7,1].match(/[acdm]{1}/)
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
def self.new_from_record(record)
|
27
|
+
rec = BookRecord.new
|
28
|
+
record.instance_variables.each { | var |
|
29
|
+
rec.instance_variable_set(var, record.instance_variable_get(var))
|
30
|
+
}
|
31
|
+
return Exception.new("Incorrect type declaration in leader") unless rec.is_valid_type?
|
32
|
+
return Exception.new("Incorrect bibliographic declaration in leader") unless rec.is_valid_blvl?
|
33
|
+
return rec
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module BookType
|
2
|
+
include RecordType
|
3
|
+
public :is_govdoc?, :nature_of_contents, :is_conference?, :audience_level, :form, :has_index?
|
4
|
+
# Checks the leader and any 006 fields to
|
5
|
+
# determine if the record is a manuscript.
|
6
|
+
# Returns a boolean.
|
7
|
+
def is_manuscript?
|
8
|
+
return true if @leader[6,1] == 't'
|
9
|
+
@fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
|
10
|
+
return true if fxd_fld[0,1] == 't'
|
11
|
+
}
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_manuscript(value=false, field=nil)
|
16
|
+
if field
|
17
|
+
return Exception.new("Field is not an 006") unless field.tag == '006'
|
18
|
+
if value
|
19
|
+
field.value[0] = 't'
|
20
|
+
else
|
21
|
+
field.value[0] = 'a'
|
22
|
+
end
|
23
|
+
else
|
24
|
+
if value
|
25
|
+
@leader[6] = 't'
|
26
|
+
else
|
27
|
+
@leader[6] = 'a'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def literary_form(human_readable=false)
|
33
|
+
lit_map={'0'=>'Non-fiction', '1'=>'Fiction', 'c'=>'Comic',
|
34
|
+
'd'=>'Drama', 'e'=>'Essay', 'f'=>'Novel', 'h'=>'Humor/satire', 'i'=>'Letter', 'j'=>'Short story',
|
35
|
+
'm'=>'Mixed', 'p'=>'Poetry', 's'=>'Speech', 'u'=>'Unknown'}
|
36
|
+
human_readable = lit_map if human_readable
|
37
|
+
return self.field_parser({:match=>'BKS', :start=>33,:end=>1}, {:match=>/[at]{1}/, :start=>16,:end=>1}, human_readable)
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_biography?(human_readable=false)
|
41
|
+
biog_map = {'a'=>'Autobiography', 'b'=>'Individual biography',
|
42
|
+
'c'=>'Collective biography', 'd'=>'Contains biographical information'}
|
43
|
+
human_readable = biog_map if human_readable
|
44
|
+
return self.field_parser({:match=>'BKS', :start=>34,:end=>1}, {:match=>/[at]{1}/, :start=>17,:end=>1}, human_readable)
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_festschrift?
|
48
|
+
return true if self['008'].value[30,1] == "1" and @record_type == "BKS"
|
49
|
+
@fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
|
50
|
+
next unless fxd_fld.value[0,1].match(/[at]{1}/) and fxd_fld.value[13,1] == "1"
|
51
|
+
return true
|
52
|
+
}
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_illustrated?(human_readable=false)
|
57
|
+
ills_map = {'a'=>'Illustrations','b'=>'Maps','c'=>'Portraits','d'=>'Charts',
|
58
|
+
'e'=>'Plans', 'f'=>'Plates', 'g'=>'Music', 'h'=>'Facsimilies', 'i'=>'Coats of arms',
|
59
|
+
'j'=>'Genealogical tables', 'k'=>'Forms', 'l'=>'Samples',
|
60
|
+
'm'=>'Phonodisc', 'o'=>'Photographs', 'p'=>'Illuminations'}
|
61
|
+
|
62
|
+
contents = []
|
63
|
+
if self.record_type == 'BKS'
|
64
|
+
self['008'].value[18,4].split(//).each { | char |
|
65
|
+
next if char == " "
|
66
|
+
if human_readable
|
67
|
+
contents << ills_map[char] if ills_map[char]
|
68
|
+
else
|
69
|
+
contents << char
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
@fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
|
74
|
+
next unless fxd_fld.value[0,1].match(/[at]{1}/)
|
75
|
+
fxd_fld.value[1,4].split(//).each { | char |
|
76
|
+
next if char == " "
|
77
|
+
if human_readable
|
78
|
+
contents << ills_map[char] if ills_map[char]
|
79
|
+
else
|
80
|
+
contents << char
|
81
|
+
end
|
82
|
+
}
|
83
|
+
}
|
84
|
+
return false if contents.empty?
|
85
|
+
return contents
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MARC
|
2
|
+
|
3
|
+
# A class that represents an individual MARC record. Every record
|
4
|
+
# is made up of a collection of MARC::Field objects.
|
5
|
+
|
6
|
+
class ComputerRecord < Record
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@leader[6] = 'm' if @leader[6,1] == ' '
|
11
|
+
@leader[7] = 'm' if @leader[7,1] == ' '
|
12
|
+
@record_type = 'COM'
|
13
|
+
@bibliographic_level = @leader.get_blvl
|
14
|
+
self.extend ComputerType
|
15
|
+
self.inspect_fixed_fields
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_valid_type?
|
19
|
+
return false unless @leader[6,1].match('m')
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
def is_valid_blvl?
|
23
|
+
return false unless @leader[7,1].match(/[abcdims]{1}/)
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
def self.new_from_record(record)
|
27
|
+
rec = ComputerRecord.new
|
28
|
+
record.instance_variables.each { | var |
|
29
|
+
rec.instance_variable_set(var, record.instance_variable_get(var))
|
30
|
+
}
|
31
|
+
return Exception.new("Incorrect type declaration in leader") unless rec.is_valid_type?
|
32
|
+
return Exception.new("Incorrect bibliographic declaration in leader") unless rec.is_valid_blvl?
|
33
|
+
return rec
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ComputerType
|
2
|
+
include RecordType
|
3
|
+
public :form, :audience_level, :is_govdoc?
|
4
|
+
def file_type(human_readable=false)
|
5
|
+
return false unless self.contains_type?("COM")
|
6
|
+
file_map = {'a'=>'Numeric data', 'b'=>'Computer program', 'c'=>'Representational',
|
7
|
+
'd'=>'Document', 'e'=>'Bibliographic data', 'f'=>'Font', 'g'=>'Game',
|
8
|
+
'h'=>'Sounds', 'i'=>'Interactive multimedia', 'j'=>'Online', 'm'=>'Combination',
|
9
|
+
'u'=>'Unknown', 'z'=>'Other'}
|
10
|
+
human_readable = file_map if human_readable
|
11
|
+
return self.field_parser({:match=>'COM', :start=>26,:end=>1}, {:match=>'m', :start=>9,:end=>1}, human_readable)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module MARC
|
2
|
+
|
3
|
+
# A class for accessing the MARC Leader
|
4
|
+
class Leader < String
|
5
|
+
attr_reader :leader, :record_type, :bibliographic_level, :encoding_level, :fixed_fields
|
6
|
+
def initialize(leader)
|
7
|
+
super
|
8
|
+
# leader defaults:
|
9
|
+
# http://www.loc.gov/marc/bibliographic/ecbdldrd.html
|
10
|
+
self[10..11] = '22'
|
11
|
+
self[20..23] = '4500'
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse_leader
|
15
|
+
self.get_type
|
16
|
+
self.get_blvl
|
17
|
+
self.get_elvl
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_type_code
|
21
|
+
return self[6,1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_blvl_code
|
25
|
+
return self[7,1]
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_type
|
29
|
+
return @record_type = self.type_translator(self.get_type_code, self.get_blvl_code)
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_archival?
|
33
|
+
return true if self[8,1] == 'a'
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_blvl
|
38
|
+
blvls = {
|
39
|
+
'a'=>'Monographic component part',
|
40
|
+
'b'=>'Serial component part',
|
41
|
+
'c'=>'Collection',
|
42
|
+
'd'=>'Subunit',
|
43
|
+
'i'=>'Integrating resource',
|
44
|
+
'm'=>'Monograph/Item',
|
45
|
+
's'=>'Serial'
|
46
|
+
}
|
47
|
+
return @bibliographic_level = blvls[self.get_blvl_code]
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_type(type)
|
51
|
+
if type.length == 1
|
52
|
+
translated_type = self.types(type)
|
53
|
+
raise ArgumentError, "Invalid Type" if translated_type.nil?
|
54
|
+
elsif type.length > 1
|
55
|
+
translated_type = type
|
56
|
+
type = self.types(type)
|
57
|
+
raise ArgumentError, "Invalid Type" if type.nil?
|
58
|
+
else
|
59
|
+
raise ArgumentError, "Invalid Type"
|
60
|
+
end
|
61
|
+
self[6] = type
|
62
|
+
end
|
63
|
+
|
64
|
+
def type_translator(type_code, blvl_code)
|
65
|
+
valid_types = ['a','t','g','k','r','o','p','e','f','c','d','i','j','m']
|
66
|
+
unless valid_types.index(type_code)
|
67
|
+
raise ArgumentError, "Invalid Type!"
|
68
|
+
return
|
69
|
+
end
|
70
|
+
rec_types = {
|
71
|
+
'BKS' => { :type => /[at]{1}/, :blvl => /[acdm]{1}/ },
|
72
|
+
'SER' => { :type => /[a]{1}/, :blvl => /[bs]{1}/ },
|
73
|
+
'VIS' => { :type => /[gkro]{1}/, :blvl => /[abcdms]{1}/ },
|
74
|
+
'MIX' => { :type => /[p]{1}/, :blvl => /[cd]{1}/ },
|
75
|
+
'MAP' => { :type => /[ef]{1}/, :blvl => /[abcdms]{1}/ },
|
76
|
+
'SCO' => { :type => /[cd]{1}/, :blvl => /[abcdms]{1}/ },
|
77
|
+
'REC' => { :type => /[ij]{1}/, :blvl => /[abcdms]{1}/ },
|
78
|
+
'COM' => { :type => /[m]{1}/, :blvl => /[abcdms]{1}/ }
|
79
|
+
}
|
80
|
+
|
81
|
+
rec_types.each_key { | type |
|
82
|
+
return type if type_code.match(rec_types[type][:type]) and blvl_code.match(rec_types[type][:blvl])
|
83
|
+
}
|
84
|
+
raise ArgumentError, "Invalid BLvl!"
|
85
|
+
return nil
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_elvl_code
|
89
|
+
return self[17,1]
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_elvl
|
93
|
+
elvls = {
|
94
|
+
' '=>'Full',
|
95
|
+
'1'=>'Full, not examined',
|
96
|
+
'2'=>'Less-than-full',
|
97
|
+
'3'=>'Abbreviated',
|
98
|
+
'4'=>'Core',
|
99
|
+
'5'=>'Partial',
|
100
|
+
'7'=>'Minimal',
|
101
|
+
'8'=>'Prepublication',
|
102
|
+
'I'=>'Full-level input by OCLC participants',
|
103
|
+
'K'=>'Less-than-full input by OCLC participants',
|
104
|
+
'L'=>'Full-level input added from a batch process',
|
105
|
+
'M'=>'Less-than-full added from a batch process',
|
106
|
+
'E'=>'System-identified MARC error in batchloaded record',
|
107
|
+
'J'=>'Deleted record'
|
108
|
+
}
|
109
|
+
return @encoding_level = elvls[self.get_elvl_code]
|
110
|
+
end
|
111
|
+
|
112
|
+
def ELvl
|
113
|
+
self.get_elvl unless @encoding_level
|
114
|
+
return @encoding_level
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_desc_code
|
118
|
+
return self[18,1]
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_desc
|
122
|
+
codes = {' '=>'Non-ISBD', 'a'=>'AACR2', 'i'=>'ISBD', 'u'=>'Unknown'}
|
123
|
+
return @descriptive_cataloging_form = codes[self.get_desc_code]
|
124
|
+
end
|
125
|
+
|
126
|
+
def Desc
|
127
|
+
self.get_desc unless @descriptive_cataloging_form
|
128
|
+
return @descriptive_cataloging_form
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|