marc4j4r 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,11 +63,11 @@
63
63
  <p class="children">
64
64
 
65
65
 
66
- <strong class="modules">Modules:</strong> <a href="MARC.html" title="MARC (module)">MARC</a>, <a href="MARC4J4R.html" title="MARC4J4R (module)">MARC4J4R</a>
66
+ <strong class="modules">Modules:</strong> <a href="MARC4J4R.html" title="MARC4J4R (module)">MARC4J4R</a>
67
67
 
68
68
 
69
69
 
70
- <strong class="classes">Classes:</strong> <a href="ASReader.html" title="ASReader (class)">ASReader</a>, <a href="ControlFieldImpl.html" title="ControlFieldImpl (class)">ControlFieldImpl</a>, <a href="DataFieldImpl.html" title="DataFieldImpl (class)">DataFieldImpl</a>, <a href="RecordImpl.html" title="RecordImpl (class)">RecordImpl</a>, <a href="SubfieldImpl.html" title="SubfieldImpl (class)">SubfieldImpl</a>
70
+ <strong class="classes">Classes:</strong> <a href="ControlFieldImpl.html" title="ControlFieldImpl (class)">ControlFieldImpl</a>, <a href="DataFieldImpl.html" title="DataFieldImpl (class)">DataFieldImpl</a>, <a href="RecordImpl.html" title="RecordImpl (class)">RecordImpl</a>, <a href="SubfieldImpl.html" title="SubfieldImpl (class)">SubfieldImpl</a>
71
71
 
72
72
 
73
73
  </p>
@@ -78,7 +78,7 @@
78
78
  </div>
79
79
 
80
80
  <div id="footer">
81
- Generated on Sat Apr 3 22:01:08 2010 by
81
+ Generated on Fri Feb 12 16:38:07 2010 by
82
82
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
83
83
  0.5.3 (ruby-1.8.7).
84
84
  </div>
@@ -0,0 +1,76 @@
1
+ require 'helper'
2
+
3
+ # one.xml
4
+ # LEADER 00000njm a2200000uu 4500
5
+ # 001 afc99990058366
6
+ # 003 DLC
7
+ # 005 20071104155141.9
8
+ # 007 sd ummunniauub
9
+ # 008 071103s1939 xxufmnne||||||||| u eng||
10
+ # 010 $a afc99990058366
11
+ # 040 $a DLC $c DLC
12
+ # 245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor.
13
+ # 260 $a Medina, Texas, $c 1939.
14
+ # 300 $a 1 sound disc : $b analog, 33 1/3 rpm, mono. ; $c 12 in.
15
+ # 651 0 $a Medina $z Texas $z United States of America.
16
+ # 700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.
17
+ # 700 1 $a Lomax, Ruby T. (Ruby Terrill) $e Recording engineer.
18
+ # 700 1 $a Taylor, Beale D. $e Singer.
19
+ # 852 $a American Folklife Center, Library of Congress
20
+ # 852 $a DLC
21
+
22
+ class TestMarc4j4r < Test::Unit::TestCase
23
+
24
+ def setup
25
+ reader = MARC4J4R.reader(File.dirname(__FILE__) + '/one.xml', :marcxml)
26
+ @r = reader.next
27
+ end
28
+
29
+ should "get the leader as a string" do
30
+ assert_equal '00000njm a2200000uu 4500', @r.leader
31
+ end
32
+
33
+ should "get all fields with the given tag" do
34
+ assert_equal 3, @r.find_by_tag('700').size
35
+ end
36
+
37
+ should "get all fields with any of the given tags" do
38
+ assert_equal 6, @r.find_by_tag(['010','700', '852']).size
39
+ end
40
+
41
+ should "get an empty array trying to find a non-existent tag" do
42
+ assert_equal [], @r.find_by_tag('002')
43
+ end
44
+
45
+ should "not return anything for a non-existent tag" do
46
+ assert_equal 1, @r.find_by_tag(['010', '002']).size
47
+ end
48
+
49
+ should "get the value of a control tag" do
50
+ assert_equal 'DLC', @r['003'].value
51
+ end
52
+
53
+ should "get a subfield value via field[]" do
54
+ assert_equal 'Sung by Beale D. Taylor.', @r['245']['c']
55
+ end
56
+
57
+ should "joing all values of a field with a space" do
58
+ assert_equal "DLC DLC", @r['040'].value
59
+ end
60
+
61
+ should "Get the first field with a given tag via []" do
62
+ assert_equal '700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.', @r['700'].to_s
63
+ end
64
+
65
+ should "get the subfield values in order of the original record" do
66
+ assert_equal ['Medina, Texas,', '1939.'], @r['260'].sub_values(['a', 'c'])
67
+ assert_equal ['Medina, Texas,', '1939.'], @r['260'].sub_values(['c', 'a'])
68
+ end
69
+
70
+ should "get the subfield values in order of the codes I pass" do
71
+ assert_equal [ '1939.', 'Medina, Texas,'], @r['260'].sub_values(['c', 'a'], true)
72
+ end
73
+
74
+
75
+
76
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marc4j4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - BillDueber
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-07 00:00:00 -04:00
12
+ date: 2010-04-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,7 @@ files:
78
78
  - test/one.dat
79
79
  - test/one.seq
80
80
  - test/one.xml
81
+ - test/test_marc4j4r.rb
81
82
  has_rdoc: true
82
83
  homepage: http://github.com/billdueber/marc4j4r
83
84
  licenses: []
@@ -109,5 +110,4 @@ summary: Use marc4j java library in JRuby in a more ruby-ish way
109
110
  test_files:
110
111
  - test/bench.rb
111
112
  - test/helper.rb
112
- - test/readtest.rb
113
- - test/t.rb
113
+ - test/test_marc4j4r.rb
data/test/readtest.rb DELETED
@@ -1,120 +0,0 @@
1
- require 'benchmark'
2
- require '../lib/marc4j4r.rb'
3
- curdir = File.dirname(__FILE__)
4
-
5
- Dir.glob("#{curdir}/../../jruby_marc_to_solr/jars/*.jar") do |x|
6
- require x
7
- end
8
-
9
- include_class Java::org.solrmarc.marc.MarcAlephSequentialReader
10
-
11
-
12
- Benchmark.bmbm do |x|
13
-
14
- x.report("Java AS") do
15
- count = 0
16
- 3.times do
17
- reader = MarcAlephSequentialReader.new(java.io.FileInputStream.new('test.seq'.to_java_string))
18
- reader.each do |r|
19
- count += 1
20
- end
21
- end
22
- # puts "AS read #{count} records"
23
- end
24
-
25
- x.report("strict") do
26
- count = 0
27
- 3.times do
28
- reader = MARC4J4R.reader('test.mrc', :strictmarc)
29
- reader.each do |r|
30
- count += 1
31
- end
32
- end
33
- # puts "Strict binary read #{count} records"
34
- end
35
-
36
- x.report("xml") do
37
- count = 0
38
- 3.times do
39
- reader = MARC4J4R.reader('test.xml', :marcxml)
40
- reader.each do |r|
41
- count += 1
42
- end
43
- end
44
- # puts "XML read #{count} records"
45
- end
46
-
47
-
48
- x.report("alephsequential") do
49
- count = 0
50
- 3.times do
51
- reader = MARC4J4R.reader('test.seq', :alephsequential)
52
- reader.each do |r|
53
- count += 1
54
- end
55
- end
56
- # puts "AS read #{count} records"
57
- end
58
-
59
-
60
-
61
-
62
- end
63
-
64
- __END__
65
- class AlephSequentialReader
66
- include Enumerable
67
- def initialize(fromwhere)
68
- stream = nil
69
- if fromwhere.is_a? Java::JavaIO::InputStream
70
- stream = fromwhere.to_io
71
- elsif fromwhere.is_a? IO
72
- stream = fromwhere
73
- else
74
- stream = File.new(fromwhere)
75
- end
76
-
77
- @handle = stream
78
- end
79
-
80
- def each
81
- record = nil
82
- currentID = nil
83
-
84
- @handle.each_line do |l|
85
- l.chomp!
86
- next unless l =~ /\S/
87
- vals = l.unpack('a9 a a3 c c a3 a*')
88
- id, tag, ind1, ind2, data = vals[0], vals[2], vals[3], vals[4], vals[6]
89
- # id, tag, ind1, ind2, junk, data = *(l.unpack('A10 a3 c c a3 A*'))
90
- if id != currentID
91
- if record
92
- yield record
93
- end
94
- record = RecordImpl.new
95
- currentID = id
96
- end
97
- if tag == 'LDR'
98
- record.setLeader(Java::org.marc4j.marc.impl.LeaderImpl.new(data))
99
- else
100
- record << buildField(tag,ind1,ind2,data)
101
- end
102
- end
103
- yield record
104
- end
105
-
106
-
107
- SUBREGEXP = /\$\$(.)/
108
- def buildField (tag, ind1, ind2, data)
109
- if Java::org.marc4j.marc.impl.Verifier.isControlField tag
110
- return Java::org.marc4j.marc.impl.ControlFieldImpl.new(tag, data)
111
- else
112
- f = Java::org.marc4j.marc.impl.DataFieldImpl.new(tag, ind1, ind2)
113
- data.split(SUBREGEXP)[1..-1].each_slice(2) do |code, value|
114
- f.addSubfield Java::org.marc4j.marc.impl.SubfieldImpl.new(code[0].ord, value)
115
- end
116
- return f
117
- end
118
- end
119
-
120
- end # End of class AlephSequentialReader
data/test/t.rb DELETED
@@ -1,6 +0,0 @@
1
- File.open('test.seq') do |f|
2
- f.each_line do |x|
3
- next unless x[10..12] == 'LDR'
4
- puts x if x.size == 43
5
- end
6
- end