marc4j4r 1.4.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.gitignore +4 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +40 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.md +164 -0
- data/Rakefile +34 -0
- data/jars/jackson-all-1.6.0.jar +0 -0
- data/jars/javamarc.jar +0 -0
- data/jars/marc4j-extra-readers-writers.jar +0 -0
- data/lib/marc4j4r.rb +73 -0
- data/lib/marc4j4r/controlfield.rb +34 -0
- data/lib/marc4j4r/datafield.rb +195 -0
- data/lib/marc4j4r/reader.rb +129 -0
- data/lib/marc4j4r/record.rb +257 -0
- data/lib/marc4j4r/version.rb +4 -0
- data/lib/marc4j4r/writer.rb +34 -0
- data/marc4j4r.gemspec +21 -0
- data/spec/alephsequentialreader_spec.rb +111 -0
- data/spec/bad.dat +1 -0
- data/spec/badbatch.dat +1 -0
- data/spec/badbatch.xml +13 -0
- data/spec/batch.dat +1 -0
- data/spec/batch.txt +193 -0
- data/spec/batch.xml +13 -0
- data/spec/chinese_utf8.dat +1 -0
- data/spec/controlfield_spec.rb +42 -0
- data/spec/datafield_spec.rb +115 -0
- data/spec/errors.seq +118 -0
- data/spec/helper.rb +21 -0
- data/spec/one.dat +1 -0
- data/spec/one.txt +17 -0
- data/spec/one.xml +4 -0
- data/spec/reader_spec.rb +112 -0
- data/spec/record_spec.rb +146 -0
- data/spec/test_marc4j4r.rb +12 -0
- data/spec/three.seq +118 -0
- metadata +116 -0
data/spec/errors.seq
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
000004262 LDR L ^^^^^nam^a22003011^^4500
|
2
|
+
000004262 001 L 000004262
|
3
|
+
000004262 005 L 19891107000000.0
|
4
|
+
000004262 006 L m^^^^^^^^d^^^^^^^^
|
5
|
+
000004262 007 L cr^bn^---auaua
|
6
|
+
000004262 008 L 880715r19721939nyua^^^^^b^^^^00100^eng^^
|
7
|
+
000004262 010 L $$a72001885/MN
|
8
|
+
000004262 020 L $$a0306705133
|
9
|
+
000004262 035 L $$a(RLIN)MIUG0297757-B
|
10
|
+
000004262 035# L $$a(CaOTULAS)159822964
|
11
|
+
000004262 035 L $$a(OCoLC)ocm00297757
|
12
|
+
000004262 035 L $$asdr-inu1221428
|
13
|
+
000004262 040 # L $$aDLC$$cDLC$$dMiU
|
14
|
+
000004262 043 L $$an------
|
15
|
+
000004262 0500 L $$aML3557$$b.D3645 1972
|
16
|
+
000004262 082 L $$a784.7/51
|
17
|
+
000004262 1001 L $$aDensmore, Frances,$$d1867-1957.
|
18
|
+
000004262 24510 L $$aNootka and Quileute music.
|
19
|
+
000004262 260 L $$aNew York,$$bDa Capo Press,$$c1972.
|
20
|
+
000004262 300 L $$axxvi, 358 p.$$billus.$$c23 cm.
|
21
|
+
000004262 4900 L $$aDa Capo Press music reprint series
|
22
|
+
000004262 500 L $$aReprint of the 1939 ed., which was issued as Bulletin 124 of Smithsonian Institution. Bureau of American Ethnology.
|
23
|
+
000004262 504 L $$aBibliography: p. 349.
|
24
|
+
000004262 538 L $$aMode of access: Internet.
|
25
|
+
000004262 650 0 L $$aNootka Indians$$xMusic.
|
26
|
+
000004262 650 0 L $$aQuileute Indians$$xMusic.
|
27
|
+
000004262 8520 L $$aMiU$$bMUSIC$$hML3557 .D4255 1972
|
28
|
+
000004262 852 L $$ainu$$bSDR$$cINU
|
29
|
+
000004262 970 L $$aBK$$bBook
|
30
|
+
000004262 970 L $$aCE$$bElectronic Resource
|
31
|
+
000004262 971 L $$aMiU
|
32
|
+
000004262 972 L $$c20040625
|
33
|
+
000004262 973 L $$aHT$$bavail_ht
|
34
|
+
000004262 973 L $$aAC$$bavail_circ
|
35
|
+
000004262 974 L $$uinu.30000053901769$$ric$$d20100226
|
36
|
+
000004262 998 L $$s9665
|
37
|
+
000005951 LDR L ^^^^^nam^a22002771^^4500
|
38
|
+
000005951 001 L 000005951
|
39
|
+
000005951 005 L 19970922000000.0
|
40
|
+
000005951 006 L m^^^^^^^^d^^^^^^^^
|
41
|
+
000005951 007 L cr^bn^---auaua
|
42
|
+
000005951 008 L 880715s1968^^^^dcu^^^^^^b^^^|00010^eng^c
|
43
|
+
000005951 010 L ahew68000006
|
44
|
+
000005951 035 L $$a(RLIN)MIUG0425743-B
|
45
|
+
000005951 035 L $$a(CaOTULAS)159824865
|
46
|
+
000005951 035 L $$a(OCoLC)ocm00425743
|
47
|
+
000005951 035 L $$asdr-ucsc.b16458175
|
48
|
+
000005951 040 L $$a*U.S. Dept. of Health Education, and Welfare. Li$$cDLC$$dMiU
|
49
|
+
000005951 0500 L $$aHD7123$$b.A39 no. 22
|
50
|
+
000005951 082 L $$a301.5/5
|
51
|
+
000005951 1001 L $$aKreps, Juanita Morris.
|
52
|
+
000005951 24510 L $$aLifetime allocation of work and leisure,$$cby Juanita M. Kreps.
|
53
|
+
000005951 260 L $$a[Washington,$$bFor sale by Supt. of Docs., U.S. Govt. Print. Off.,$$c1968]
|
54
|
+
000005951 300 L $$aix, 44 p.$$c24 cm.
|
55
|
+
000005951 4901 L $$aUnited States. Social Security Administration. Office of Research and Statistics. Research report$$vno. 22
|
56
|
+
000005951 504 L $$aBibliographical footnotes.
|
57
|
+
000005951 538 L $$aMode of access: Internet.
|
58
|
+
000005951 650 0 L $$aAge and employment
|
59
|
+
000005951 650 0 L $$aRetirement
|
60
|
+
000005951 830 0 L $$aResearch report (United States. Social Security Administration. Office of Research and Statistics) ;$$vno. 22
|
61
|
+
000005951 8520 L $$aMiU$$bTAUB$$hHD6279 .K925
|
62
|
+
000005951 8520 L $$aMiU$$bTAUB$$hHD 7123 .A28 no.22
|
63
|
+
000005951 8520 L $$aMiU$$bBUHR$$cGRAD$$hHD 7123 .A28 no.22
|
64
|
+
000005951 852 L $$auc1$$bSDR$$cUCSC
|
65
|
+
000005951 970 L $$aBK$$bBook
|
66
|
+
000005951 970 L $$aCE$$bElectronic Resource
|
67
|
+
000005951 971 L $$aMiU
|
68
|
+
000005951 972 L $$c20040625
|
69
|
+
000005951 972 L $$c20040625
|
70
|
+
000005951 972 L $$c20040625
|
71
|
+
000005951 973 L $$aHT$$bavail_ht
|
72
|
+
000005951 973 L $$aAC$$bavail_circ
|
73
|
+
000005951 974 L $$umdp.39015038814847$$ric
|
74
|
+
000005951 974 L $$umdp.39015072105847$$ric$$d20091001
|
75
|
+
000005951 974 L $$zno.22$$uuc1.32106000924198$$ric$$d20091202
|
76
|
+
000005951 998 L $$s9665
|
77
|
+
000009811 LDR L ^^^^^nam^a22003251^^4500
|
78
|
+
000009811 001 L 000009811
|
79
|
+
000009811 005 L 19970922000000.0
|
80
|
+
000009811 006 L m^^^^^^^^d^^^^^^^^
|
81
|
+
000009811 007 L cr^bn^---auaua
|
82
|
+
000009811 008 L 880715s1971^^^^dcua^^^^^bs^^^00000^eng^^
|
83
|
+
000009811 010 L $$a72179703
|
84
|
+
000009811 035 L $$a(RLIN)MIUG0695316-B
|
85
|
+
000009811 035 L $$a(CaOTULAS)159829127
|
86
|
+
000009811 035 L $$a(OCoLC)ocm00695316
|
87
|
+
000009811 035 L $$asdr-ucsc.b13985097
|
88
|
+
000009811 040 L $$aDLC$$cDLC$$dMiU$$dCStRLIN
|
89
|
+
000009811 043 L $$an-us---
|
90
|
+
000009811 0500 L $$aHD7123$$b.A39 no. 37$$aHD7102.U4
|
91
|
+
000009811 082 L $$a368.4/00973 s$$a368.4/2/00973
|
92
|
+
000009811 086 L $$aII0 aHE 3.49:37
|
93
|
+
000009811 1101 L $$aUnited States.$$bSocial Security Administration.$$bOffice of Research and Statistics.
|
94
|
+
000009811 24510 L $$aFinancing mental health care under medicare and medicaid.
|
95
|
+
000009811 260 L $$a[Washington;$$bFor sale by the Supt. of Docs., U.S. Govt. Print. Off.,$$c1971]
|
96
|
+
000009811 300 L $$avii, 52 p.$$billus.$$c27 cm.
|
97
|
+
000009811 4901 L $$aIts Research report$$vno. 37
|
98
|
+
000009811 500 L $$aSupt. of Docs. no.: HE 3.49:37
|
99
|
+
000009811 504 L $$aIncludes bibliographical references.
|
100
|
+
000009811 538 L $$aMode of access: Internet.
|
101
|
+
000009811 650 0 L $$aMental health insurance$$zUnited States.
|
102
|
+
000009811 650 0 L $$aMedicare
|
103
|
+
000009811 650 0 L $$aMedicaid
|
104
|
+
000009811 830 0 L $$aResearch report (United States. Social Security Administration. Office of Research and Statistics) ;$$vno. 37
|
105
|
+
000009811 8520 L $$aMiU$$bBUHR$$cGRAD$$hHD 7123 .A28 no.37
|
106
|
+
000009811 8520 L $$aMiU$$bTAUB$$hHD 7123 .A28 no.37
|
107
|
+
000009811 852 L $$auc1$$bSDR$$cUCSC
|
108
|
+
000009811 970 L $$aBK$$bBook
|
109
|
+
000009811 970 L $$aCE$$bElectronic Resource
|
110
|
+
000009811 970 L $$aXS$$bStatistics
|
111
|
+
000009811 971 L $$aMiU
|
112
|
+
000009811 972 L $$c20040625
|
113
|
+
000009811 972 L $$c20040625
|
114
|
+
000009811 973 L $$aHT$$bavail_ht
|
115
|
+
000009811 973 L $$aAC$$bavail_circ
|
116
|
+
000009811 974 L $$zno.37$$umdp.39015004063635$$ric
|
117
|
+
000009811 974 L $$zno.37$$uuc1.32106000924313$$ric$$d20091202
|
118
|
+
000009811 998 L $$s9665
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
warn e.message
|
7
|
+
warn "Run `gem install bundler` to install Bundler."
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:default, :development, :test)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
warn e.message
|
15
|
+
warn "Run `bundle install` to install missing gems."
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'minitest/autorun'
|
20
|
+
require 'marc4j4r'
|
21
|
+
DIR = File.dirname(__FILE__)
|
data/spec/one.dat
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
00734njm a2200217uu 4500001001500000003000400015005001700019007001500036008004100051010001900092040001300111245006800124260002600192300005600218651004500274700005400319700005500373700003000428852005000458852000800508afc99990058366DLC20071104155141.9sd ummunniauub071103s1939 xxufmnne||||||||| u eng|| aafc99990058366 aDLCcDLC04aThe Texas rangerh[sound recording] /cSung by Beale D. Taylor. aMedina, Texas,c1939. a1 sound disc :banalog, 33 1/3 rpm, mono. ;c12 in. 0aMedinazTexaszUnited States of America.1 aLomax, John Avery, 1867-1948eRecording engineer.1 aLomax, Ruby T. (Ruby Terrill)eRecording engineer.1 aTaylor, Beale D.eSinger. aAmerican Folklife Center, Library of Congress aDLC
|
data/spec/one.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
LEADER 00734njm a2200217uu 4500
|
2
|
+
001 afc99990058366
|
3
|
+
003 DLC
|
4
|
+
005 20071104155141.9
|
5
|
+
007 sd ummunniauub
|
6
|
+
008 071103s1939 xxufmnne||||||||| u eng||
|
7
|
+
010 $a afc99990058366
|
8
|
+
040 $a DLC $c DLC
|
9
|
+
245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor.
|
10
|
+
260 $a Medina, Texas, $c 1939.
|
11
|
+
300 $a 1 sound disc : $b analog, 33 1/3 rpm, mono. ; $c 12 in.
|
12
|
+
651 0 $a Medina $z Texas $z United States of America.
|
13
|
+
700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.
|
14
|
+
700 1 $a Lomax, Ruby T. (Ruby Terrill) $e Recording engineer.
|
15
|
+
700 1 $a Taylor, Beale D. $e Singer.
|
16
|
+
852 $a American Folklife Center, Library of Congress
|
17
|
+
852 $a DLC
|
data/spec/one.xml
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<collection xmlns='http://www.loc.gov/MARC21/slim' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd'>
|
3
|
+
<record><leader>00734njm a2200217uu 4500</leader><controlfield tag='001'>afc99990058366</controlfield><controlfield tag='003'>DLC</controlfield><controlfield tag='005'>20071104155141.9</controlfield><controlfield tag='007'>sd ummunniauub</controlfield><controlfield tag='008'>071103s1939 xxufmnne||||||||| u eng||</controlfield><datafield tag='010' ind1=' ' ind2=' '><subfield code='a'>afc99990058366</subfield></datafield><datafield tag='040' ind1=' ' ind2=' '><subfield code='a'>DLC</subfield><subfield code='c'>DLC</subfield></datafield><datafield tag='245' ind1='0' ind2='4'><subfield code='a'>The Texas ranger</subfield><subfield code='h'>[sound recording] /</subfield><subfield code='c'>Sung by Beale D. Taylor.</subfield></datafield><datafield tag='260' ind1=' ' ind2=' '><subfield code='a'>Medina, Texas,</subfield><subfield code='c'>1939.</subfield></datafield><datafield tag='300' ind1=' ' ind2=' '><subfield code='a'>1 sound disc :</subfield><subfield code='b'>analog, 33 1/3 rpm, mono. ;</subfield><subfield code='c'>12 in.</subfield></datafield><datafield tag='651' ind1=' ' ind2='0'><subfield code='a'>Medina</subfield><subfield code='z'>Texas</subfield><subfield code='z'>United States of America.</subfield></datafield><datafield tag='700' ind1='1' ind2=' '><subfield code='a'>Lomax, John Avery, 1867-1948</subfield><subfield code='e'>Recording engineer.</subfield></datafield><datafield tag='700' ind1='1' ind2=' '><subfield code='a'>Lomax, Ruby T. (Ruby Terrill)</subfield><subfield code='e'>Recording engineer.</subfield></datafield><datafield tag='700' ind1='1' ind2=' '><subfield code='a'>Taylor, Beale D.</subfield><subfield code='e'>Singer.</subfield></datafield><datafield tag='852' ind1=' ' ind2=' '><subfield code='a'>American Folklife Center, Library of Congress</subfield></datafield><datafield tag='852' ind1=' ' ind2=' '><subfield code='a'>DLC</subfield></datafield></record>
|
4
|
+
</collection>
|
data/spec/reader_spec.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe "MARC4J4R_reader" do
|
6
|
+
it "can read binary" do
|
7
|
+
reader = MARC4J4R::Reader.new("#{DIR}/one.dat")
|
8
|
+
rec = reader.first
|
9
|
+
rec['245']['a'].must_equal "The Texas ranger"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can read XML" do
|
13
|
+
reader = MARC4J4R::Reader.new("#{DIR}/one.xml", :marcxml)
|
14
|
+
rec = reader.first
|
15
|
+
rec['245']['a'].must_equal "The Texas ranger"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "enumerates through all binary records" do
|
19
|
+
reader = MARC4J4R::Reader.new("#{DIR}/batch.dat")
|
20
|
+
recs = reader.collect {|a| a}
|
21
|
+
recs.size.must_equal 10
|
22
|
+
end
|
23
|
+
|
24
|
+
it "enumerates through all XML records" do
|
25
|
+
reader = MARC4J4R::Reader.new("#{DIR}/batch.xml", :marcxml)
|
26
|
+
recs = reader.collect {|a| a}
|
27
|
+
recs.size.must_equal 10
|
28
|
+
end
|
29
|
+
|
30
|
+
it "Bails if passed an illegal type" do
|
31
|
+
lambda{reader = MARC4J4R::Reader.new("#{DIR}/batch.xml", :marc)}.must_raise(ArgumentError).message.must_match(/^Reader type/)
|
32
|
+
end
|
33
|
+
it "Bails if passed an illegal encoding" do
|
34
|
+
lambda{reader = MARC4J4R::Reader.new("#{DIR}/batch.xml", :strictmarc, :utf)}.must_raise(ArgumentError).message.must_match(/^Encoding/)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Reader encodings, strict reader" do
|
39
|
+
it "Works with UTF-8 without explicit encoding" do
|
40
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat")
|
41
|
+
r = reader.first
|
42
|
+
second_title = r.find_by_tag('245')[1]
|
43
|
+
second_title['a'].must_equal "湘鄂贛苏区史稿 /"
|
44
|
+
end
|
45
|
+
it "Works with UTF-8, explicit encoding" do
|
46
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat", :strictmarc, :utf8)
|
47
|
+
r = reader.first
|
48
|
+
second_title = r.find_by_tag('245')[1]
|
49
|
+
second_title['a'].must_equal "湘鄂贛苏区史稿 /"
|
50
|
+
end
|
51
|
+
it "Fails with UTF-8, wrong explicit encoding" do
|
52
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat", :strictmarc, :marc8)
|
53
|
+
r = reader.first
|
54
|
+
second_title = r.find_by_tag('245')[1]
|
55
|
+
second_title['a'].wont_equal "湘鄂贛苏区史稿 /"
|
56
|
+
end
|
57
|
+
it "Fails with UTF-8, wrong explicit encoding" do
|
58
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat", :strictmarc, :iso)
|
59
|
+
r = reader.first
|
60
|
+
second_title = r.find_by_tag('245')[1]
|
61
|
+
second_title['a'].wont_equal "湘鄂贛苏区史稿 /"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "Reader encodings, permissive reader" do
|
66
|
+
|
67
|
+
|
68
|
+
it "Works with UTF-8 without explicit encoding" do
|
69
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat", :permissivemarc)
|
70
|
+
r = reader.first
|
71
|
+
second_title = r.find_by_tag('245')[1]
|
72
|
+
second_title['a'].must_equal "湘鄂贛苏区史稿 /"
|
73
|
+
end
|
74
|
+
it "Works with UTF-8, explicit encoding" do
|
75
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat", :permissivemarc, :utf8)
|
76
|
+
r = reader.first
|
77
|
+
second_title = r.find_by_tag('245')[1]
|
78
|
+
second_title['a'].must_equal "湘鄂贛苏区史稿 /"
|
79
|
+
end
|
80
|
+
it "Fails with UTF-8, wrong explicit encoding" do
|
81
|
+
reader = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat", :permissivemarc, :iso)
|
82
|
+
r = reader.first
|
83
|
+
second_title = r.find_by_tag('245')[1]
|
84
|
+
second_title['a'].must_equal "湘鄂贛苏区史稿 /" # equal, because it's permissive and tries to do the right thing
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
describe "Reader round-tripping" do
|
94
|
+
before do
|
95
|
+
@one = MARC4J4R::Reader.new("#{DIR}/one.dat").first
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should round-trip binary" do
|
99
|
+
rt = MARC4J4R::Reader.new(StringIO.new(@one.to_marc)).first
|
100
|
+
rt.must_equal @one
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should round-trip xml" do
|
104
|
+
rt = MARC4J4R::Reader.new(StringIO.new(@one.to_xml), :marcxml).first
|
105
|
+
rt.must_equal @one
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should show xml and binary forms equal after parsing" do
|
109
|
+
rt = MARC4J4R::Reader.new("#{DIR}/one.xml", :marcxml).first
|
110
|
+
rt.must_equal @one
|
111
|
+
end
|
112
|
+
end
|
data/spec/record_spec.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
# LEADER 00734njm a2200217uu 4500
|
4
|
+
# 001 afc99990058366
|
5
|
+
# 003 DLC
|
6
|
+
# 005 20071104155141.9
|
7
|
+
# 007 sd ummunniauub
|
8
|
+
# 008 071103s1939 xxufmnne||||||||| u eng||
|
9
|
+
# 010 $a afc99990058366
|
10
|
+
# 040 $a DLC $c DLC
|
11
|
+
# 245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor.
|
12
|
+
# 260 $a Medina, Texas, $c 1939.
|
13
|
+
# 300 $a 1 sound disc : $b analog, 33 1/3 rpm, mono. ; $c 12 in.
|
14
|
+
# 651 0 $a Medina $z Texas $z United States of America.
|
15
|
+
# 700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.
|
16
|
+
# 700 1 $a Lomax, Ruby T. (Ruby Terrill) $e Recording engineer.
|
17
|
+
# 700 1 $a Taylor, Beale D. $e Singer.
|
18
|
+
# 852 $a American Folklife Center, Library of Congress
|
19
|
+
# 852 $a DLC
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
describe "MARC4J4R_basic_retrieval_stuff" do
|
26
|
+
before do
|
27
|
+
@one = MARC4J4R::Reader.new("#{DIR}/one.dat").first
|
28
|
+
@batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can get the leader" do
|
32
|
+
@one.leader.must_equal "00734njm a2200217uu 4500"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can set the leader" do
|
36
|
+
@one.leader = "00734njm 2200217uu 4500"
|
37
|
+
@one.leader.must_equal "00734njm 2200217uu 4500"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "disallows bad leaders" do
|
41
|
+
lambda{
|
42
|
+
@one.leader = 'Hello World'
|
43
|
+
}.must_raise RuntimeError
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can read a control field correctly" do
|
47
|
+
@one['001'].value.must_equal "afc99990058366"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can find all the fields" do
|
51
|
+
fields = @one.collect {|a| a}
|
52
|
+
fields.size.must_equal 16
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should get the first 245 for this record" do
|
56
|
+
@one['245'].to_s.must_equal "245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor."
|
57
|
+
end
|
58
|
+
|
59
|
+
it "finds nothing when there's nothign there" do
|
60
|
+
@one['035'].must_equal nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "MARC4J4R::Record #find_by_tag" do
|
65
|
+
before do
|
66
|
+
@one = MARC4J4R::Reader.new("#{DIR}/one.dat").first
|
67
|
+
@df = MARC4J4R::DataField.new('260')
|
68
|
+
@df << MARC4J4R::SubField.new('a', 'Medina, Texas,')
|
69
|
+
@df << MARC4J4R::SubField.new('c', '1939.')
|
70
|
+
|
71
|
+
@cf = MARC4J4R::ControlField.new('005', '20071104155141.9')
|
72
|
+
|
73
|
+
@batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect
|
74
|
+
@utf8 = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat").first
|
75
|
+
end
|
76
|
+
|
77
|
+
it "gets an empty array for non-existant tag(s)" do
|
78
|
+
@one.find_by_tag('999').must_equal []
|
79
|
+
end
|
80
|
+
|
81
|
+
it "gets an empty arry for set of non-existant tags" do
|
82
|
+
@one.find_by_tag(['998', '999']).must_equal []
|
83
|
+
end
|
84
|
+
|
85
|
+
it "gets a single field for the 260 as string" do
|
86
|
+
onetag = @one.find_by_tag('260')
|
87
|
+
onetag.must_equal [@df]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "gets a single field for the 260 as an array" do
|
91
|
+
onetag = @one.find_by_tag('260')
|
92
|
+
@one.find_by_tag(['260']).must_equal [@df]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "gets both the 260 and 005" do
|
96
|
+
@one.find_by_tag(['005', '260']).must_equal [@cf, @df]
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns fields in the order their tags were requested" do
|
100
|
+
@one.find_by_tag(['260', '005']).must_equal [@df, @cf]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "allows caller to force return of tags in original order" do
|
104
|
+
@one.find_by_tag(['260', '005'], true).must_equal [@cf, @df]
|
105
|
+
end
|
106
|
+
|
107
|
+
it "finds all instances of requested tags" do
|
108
|
+
@one.find_by_tag('700').size.must_equal 3
|
109
|
+
@one.find_by_tag('852').size.must_equal 2
|
110
|
+
@one.find_by_tag(['852', '700']).size.must_equal 5
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns duplicate-tag fields in the order from the record" do
|
114
|
+
first = @one['700']
|
115
|
+
@one.find_by_tag('700')[0].must_equal first
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "Format checks" do
|
121
|
+
before do
|
122
|
+
@one = MARC4J4R::Reader.new("#{DIR}/one.dat").first
|
123
|
+
@batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect {|a| a}
|
124
|
+
@utf8 = MARC4J4R::Reader.new("#{DIR}/chinese_utf8.dat").first
|
125
|
+
end
|
126
|
+
|
127
|
+
it "round trips binary" do
|
128
|
+
MARC4J4R::Record.from_string(@one.to_marc).must_equal @one
|
129
|
+
@batch.each do |r|
|
130
|
+
MARC4J4R::Record.from_string(r.to_marc).must_equal r
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "round trips utf8 record as binary" do
|
135
|
+
MARC4J4R::Record.from_string(@utf8.to_marc, :utf8).must_equal @utf8
|
136
|
+
end
|
137
|
+
|
138
|
+
it "round trips XML" do
|
139
|
+
MARC4J4R::Record.from_xml_string(@one.to_xml).must_equal @one
|
140
|
+
end
|
141
|
+
|
142
|
+
it "round trips marc-in-json" do
|
143
|
+
copy = @one.to_marc_in_json
|
144
|
+
MARC4J4R::Record.new_from_marc_in_json(copy).must_equal @one
|
145
|
+
end
|
146
|
+
end
|
data/spec/three.seq
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
000004262 LDR L ^^^^^nam^a22003011^^4500
|
2
|
+
000004262 001 L 000004262
|
3
|
+
000004262 005 L 19891107000000.0
|
4
|
+
000004262 006 L m^^^^^^^^d^^^^^^^^
|
5
|
+
000004262 007 L cr^bn^---auaua
|
6
|
+
000004262 008 L 880715r19721939nyua^^^^^b^^^^00100^eng^^
|
7
|
+
000004262 010 L $$a72001885/MN
|
8
|
+
000004262 020 L $$a0306705133
|
9
|
+
000004262 035 L $$a(RLIN)MIUG0297757-B
|
10
|
+
000004262 035 L $$a(CaOTULAS)159822964
|
11
|
+
000004262 035 L $$a(OCoLC)ocm00297757
|
12
|
+
000004262 035 L $$asdr-inu1221428
|
13
|
+
000004262 040 L $$aDLC$$cDLC$$dMiU
|
14
|
+
000004262 043 L $$an------
|
15
|
+
000004262 0500 L $$aML3557$$b.D3645 1972
|
16
|
+
000004262 082 L $$a784.7/51
|
17
|
+
000004262 1001 L $$aDensmore, Frances,$$d1867-1957.
|
18
|
+
000004262 24510 L $$aNootka and Quileute music.
|
19
|
+
000004262 260 L $$aNew York,$$bDa Capo Press,$$c1972.
|
20
|
+
000004262 300 L $$axxvi, 358 p.$$billus.$$c23 cm.
|
21
|
+
000004262 4900 L $$aDa Capo Press music reprint series
|
22
|
+
000004262 500 L $$aReprint of the 1939 ed., which was issued as Bulletin 124 of Smithsonian Institution. Bureau of American Ethnology.
|
23
|
+
000004262 504 L $$aBibliography: p. 349.
|
24
|
+
000004262 538 L $$aMode of access: Internet.
|
25
|
+
000004262 650 0 L $$aNootka Indians$$xMusic.
|
26
|
+
000004262 650 0 L $$aQuileute Indians$$xMusic.
|
27
|
+
000004262 8520 L $$aMiU$$bMUSIC$$hML3557 .D4255 1972
|
28
|
+
000004262 852 L $$ainu$$bSDR$$cINU
|
29
|
+
000004262 970 L $$aBK$$bBook
|
30
|
+
000004262 970 L $$aCE$$bElectronic Resource
|
31
|
+
000004262 971 L $$aMiU
|
32
|
+
000004262 972 L $$c20040625
|
33
|
+
000004262 973 L $$aHT$$bavail_ht
|
34
|
+
000004262 973 L $$aAC$$bavail_circ
|
35
|
+
000004262 974 L $$uinu.30000053901769$$ric$$d20100226
|
36
|
+
000004262 998 L $$s9665
|
37
|
+
000005951 LDR L ^^^^^nam^a22002771^^4500
|
38
|
+
000005951 001 L 000005951
|
39
|
+
000005951 005 L 19970922000000.0
|
40
|
+
000005951 006 L m^^^^^^^^d^^^^^^^^
|
41
|
+
000005951 007 L cr^bn^---auaua
|
42
|
+
000005951 008 L 880715s1968^^^^dcu^^^^^^b^^^|00010^eng^c
|
43
|
+
000005951 010 L $$ahew68000006
|
44
|
+
000005951 035 L $$a(RLIN)MIUG0425743-B
|
45
|
+
000005951 035 L $$a(CaOTULAS)159824865
|
46
|
+
000005951 035 L $$a(OCoLC)ocm00425743
|
47
|
+
000005951 035 L $$asdr-ucsc.b16458175
|
48
|
+
000005951 040 L $$a*U.S. Dept. of Health Education, and Welfare. Li$$cDLC$$dMiU
|
49
|
+
000005951 0500 L $$aHD7123$$b.A39 no. 22
|
50
|
+
000005951 082 L $$a301.5/5
|
51
|
+
000005951 1001 L $$aKreps, Juanita Morris.
|
52
|
+
000005951 24510 L $$aLifetime allocation of work and leisure,$$cby Juanita M. Kreps.
|
53
|
+
000005951 260 L $$a[Washington,$$bFor sale by Supt. of Docs., U.S. Govt. Print. Off.,$$c1968]
|
54
|
+
000005951 300 L $$aix, 44 p.$$c24 cm.
|
55
|
+
000005951 4901 L $$aUnited States. Social Security Administration. Office of Research and Statistics. Research report$$vno. 22
|
56
|
+
000005951 504 L $$aBibliographical footnotes.
|
57
|
+
000005951 538 L $$aMode of access: Internet.
|
58
|
+
000005951 650 0 L $$aAge and employment
|
59
|
+
000005951 650 0 L $$aRetirement
|
60
|
+
000005951 830 0 L $$aResearch report (United States. Social Security Administration. Office of Research and Statistics) ;$$vno. 22
|
61
|
+
000005951 8520 L $$aMiU$$bTAUB$$hHD6279 .K925
|
62
|
+
000005951 8520 L $$aMiU$$bTAUB$$hHD 7123 .A28 no.22
|
63
|
+
000005951 8520 L $$aMiU$$bBUHR$$cGRAD$$hHD 7123 .A28 no.22
|
64
|
+
000005951 852 L $$auc1$$bSDR$$cUCSC
|
65
|
+
000005951 970 L $$aBK$$bBook
|
66
|
+
000005951 970 L $$aCE$$bElectronic Resource
|
67
|
+
000005951 971 L $$aMiU
|
68
|
+
000005951 972 L $$c20040625
|
69
|
+
000005951 972 L $$c20040625
|
70
|
+
000005951 972 L $$c20040625
|
71
|
+
000005951 973 L $$aHT$$bavail_ht
|
72
|
+
000005951 973 L $$aAC$$bavail_circ
|
73
|
+
000005951 974 L $$umdp.39015038814847$$ric
|
74
|
+
000005951 974 L $$umdp.39015072105847$$ric$$d20091001
|
75
|
+
000005951 974 L $$zno.22$$uuc1.32106000924198$$ric$$d20091202
|
76
|
+
000005951 998 L $$s9665
|
77
|
+
000009811 LDR L ^^^^^nam^a22003251^^4500
|
78
|
+
000009811 001 L 000009811
|
79
|
+
000009811 005 L 19970922000000.0
|
80
|
+
000009811 006 L m^^^^^^^^d^^^^^^^^
|
81
|
+
000009811 007 L cr^bn^---auaua
|
82
|
+
000009811 008 L 880715s1971^^^^dcua^^^^^bs^^^00000^eng^^
|
83
|
+
000009811 010 L $$a72179703
|
84
|
+
000009811 035 L $$a(RLIN)MIUG0695316-B
|
85
|
+
000009811 035 L $$a(CaOTULAS)159829127
|
86
|
+
000009811 035 L $$a(OCoLC)ocm00695316
|
87
|
+
000009811 035 L $$asdr-ucsc.b13985097
|
88
|
+
000009811 040 L $$aDLC$$cDLC$$dMiU$$dCStRLIN
|
89
|
+
000009811 043 L $$an-us---
|
90
|
+
000009811 0500 L $$aHD7123$$b.A39 no. 37$$aHD7102.U4
|
91
|
+
000009811 082 L $$a368.4/00973 s$$a368.4/2/00973
|
92
|
+
000009811 086 L $$aII0 aHE 3.49:37
|
93
|
+
000009811 1101 L $$aUnited States.$$bSocial Security Administration.$$bOffice of Research and Statistics.
|
94
|
+
000009811 24510 L $$aFinancing mental health care under medicare and medicaid.
|
95
|
+
000009811 260 L $$a[Washington;$$bFor sale by the Supt. of Docs., U.S. Govt. Print. Off.,$$c1971]
|
96
|
+
000009811 300 L $$avii, 52 p.$$billus.$$c27 cm.
|
97
|
+
000009811 4901 L $$aIts Research report$$vno. 37
|
98
|
+
000009811 500 L $$aSupt. of Docs. no.: HE 3.49:37
|
99
|
+
000009811 504 L $$aIncludes bibliographical references.
|
100
|
+
000009811 538 L $$aMode of access: Internet.
|
101
|
+
000009811 650 0 L $$aMental health insurance$$zUnited States.
|
102
|
+
000009811 650 0 L $$aMedicare
|
103
|
+
000009811 650 0 L $$aMedicaid
|
104
|
+
000009811 830 0 L $$aResearch report (United States. Social Security Administration. Office of Research and Statistics) ;$$vno. 37
|
105
|
+
000009811 8520 L $$aMiU$$bBUHR$$cGRAD$$hHD 7123 .A28 no.37
|
106
|
+
000009811 8520 L $$aMiU$$bTAUB$$hHD 7123 .A28 no.37
|
107
|
+
000009811 852 L $$auc1$$bSDR$$cUCSC
|
108
|
+
000009811 970 L $$aBK$$bBook
|
109
|
+
000009811 970 L $$aCE$$bElectronic Resource
|
110
|
+
000009811 970 L $$aXS$$bStatistics
|
111
|
+
000009811 971 L $$aMiU
|
112
|
+
000009811 972 L $$c20040625
|
113
|
+
000009811 972 L $$c20040625
|
114
|
+
000009811 973 L $$aHT$$bavail_ht
|
115
|
+
000009811 973 L $$aAC$$bavail_circ
|
116
|
+
000009811 974 L $$zno.37$$umdp.39015004063635$$ric
|
117
|
+
000009811 974 L $$zno.37$$uuc1.32106000924313$$ric$$d20091202
|
118
|
+
000009811 998 L $$s9665
|