marc_alephsequential 0.1.0
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.
- checksums.yaml +15 -0
- data/.document +3 -0
- data/.gitignore +4 -0
- data/.travis.yml +10 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +20 -0
- data/README.md +103 -0
- data/Rakefile +38 -0
- data/lib/marc_alephsequential/asline.rb +161 -0
- data/lib/marc_alephsequential/asline_group.rb +101 -0
- data/lib/marc_alephsequential/asline_reader.rb +16 -0
- data/lib/marc_alephsequential/buffered_linereader.rb +100 -0
- data/lib/marc_alephsequential/error.rb +13 -0
- data/lib/marc_alephsequential/log.rb +20 -0
- data/lib/marc_alephsequential/reader.rb +54 -0
- data/lib/marc_alephsequential/version.rb +4 -0
- data/lib/marc_alephsequential.rb +9 -0
- data/marc_alephsequential.gemspec +20 -0
- data/spec/asline_group_spec.rb +59 -0
- data/spec/asline_spec.rb +46 -0
- data/spec/data/batch.seq +1000 -0
- data/spec/data/newline.seq +33 -0
- data/spec/data/no_initial_subfield.seq +34 -0
- data/spec/data/noleader.seq +33 -0
- data/spec/data/single.seq +34 -0
- data/spec/helper.rb +22 -0
- data/spec/reader_spec.rb +62 -0
- data/spec/version_spec.rb +10 -0
- metadata +84 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'marc'
|
2
|
+
require 'yell'
|
3
|
+
require 'marc_alephsequential/asline_reader'
|
4
|
+
require 'marc_alephsequential/asline_group'
|
5
|
+
require 'marc_alephsequential/log'
|
6
|
+
|
7
|
+
module MARC
|
8
|
+
module AlephSequential
|
9
|
+
|
10
|
+
class Reader
|
11
|
+
|
12
|
+
include Enumerable
|
13
|
+
include Log
|
14
|
+
|
15
|
+
attr_reader :lines
|
16
|
+
attr_accessor :current_id
|
17
|
+
|
18
|
+
def initialize(filename_or_io, opts={})
|
19
|
+
@areader = ASLineReader.new(filename_or_io)
|
20
|
+
end
|
21
|
+
|
22
|
+
def each
|
23
|
+
|
24
|
+
unless block_given?
|
25
|
+
return enum_for(:each)
|
26
|
+
end
|
27
|
+
|
28
|
+
agroup = ASLineGroup.new
|
29
|
+
|
30
|
+
while @areader.has_next?
|
31
|
+
nextid = @areader.peek.id
|
32
|
+
if nextid != @current_id && @areader.peek.valid_id?
|
33
|
+
yield agroup.to_record unless agroup.empty?
|
34
|
+
agroup = ASLineGroup.new
|
35
|
+
@current_id = nextid
|
36
|
+
else
|
37
|
+
agroup.add @areader.next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# yield whatever is left, unless there's nothing left
|
41
|
+
yield agroup.to_record unless agroup.empty?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/marc_alephsequential/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "marc_alephsequential"
|
7
|
+
gem.version = MarcAlephsequential::VERSION
|
8
|
+
gem.summary = %q{ruby-marc reader for Aleph sequential files}
|
9
|
+
gem.description = %q{A ruby-marc reader for Aleph sequential files, a MARC serialization supported by Ex Libris' Aleph}
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["Bill Dueber"]
|
12
|
+
gem.email = "bill@dueber.com"
|
13
|
+
gem.homepage = "https://github.com/billdueber/marc_alephsequential#readme"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'marc_alephsequential'
|
3
|
+
|
4
|
+
describe "ASLineGroup" do
|
5
|
+
before do
|
6
|
+
@single_lines = File.open('spec/data/single.seq').read.split("\n")
|
7
|
+
@full = MARC::AlephSequential::ASLineGroup.new
|
8
|
+
@single_lines.each_with_index {|l,i| @full.add_string(l,i ) }
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Create Group" do
|
13
|
+
before do
|
14
|
+
@ag = MARC::AlephSequential::ASLineGroup.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should start empty" do
|
18
|
+
@ag.must_be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should read in a valid record" do
|
22
|
+
@ag = MARC::AlephSequential::ASLineGroup.new
|
23
|
+
File.open('spec/data/single.seq').each_with_index {|l,i| @ag.add_string(l,i ) }
|
24
|
+
@ag.size.must_equal 33
|
25
|
+
@ag.leader.must_equal ' nam a22003011 4500'
|
26
|
+
@ag.aslines[0].tag.must_equal '001'
|
27
|
+
@ag.aslines[1].tag.must_equal '003'
|
28
|
+
@ag.aslines[1].type.must_equal :control
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should deal with embedded newlines" do
|
32
|
+
tinyrec = [
|
33
|
+
"000000794 LDR L ^^^^^nam^a22003011^^4500",
|
34
|
+
"000000794 001 L 000000794",
|
35
|
+
"000000794 005 L 19880715000000.0",
|
36
|
+
"000000794 1001 L $$aClark, Albert ",
|
37
|
+
"Curtis,$$d1859-1937.",
|
38
|
+
"000000794 24514 L $$aThe descent of manuscripts"
|
39
|
+
]
|
40
|
+
|
41
|
+
tinyrec.each_with_index {|l,i| @ag.add_string(l,i) }
|
42
|
+
field = @ag.aslines[2].to_field
|
43
|
+
field.tag.must_equal '100'
|
44
|
+
field['a'].must_equal 'Clark, Albert Curtis,'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should produce a good record" do
|
48
|
+
rec = @full.to_record
|
49
|
+
rec['001'].value.must_equal '000000794'
|
50
|
+
rec['998'].value.must_equal '9665'
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
end
|
data/spec/asline_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'marc_alephsequential'
|
3
|
+
|
4
|
+
describe 'ASLine' do
|
5
|
+
before do
|
6
|
+
@leader = '000000794 LDR L ^^^^^nam^a22003011^^4500'
|
7
|
+
@c1 = '000000794 008 L 880715r19701918enk^^^^^^b^^^|00100^eng^^'
|
8
|
+
@c2 = '000000794 001 L 000000794'
|
9
|
+
@d1 = '000000794 1001 L $$aClark, Albert Curtis,$$d1859-1937.'
|
10
|
+
@d2 = '000000794 60000 L $$aPlato.$$tCritias$$xManuscripts.'
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
it "correctly parses a leader" do
|
15
|
+
aline = MARC::AlephSequential::ASLine.new(@leader, 1)
|
16
|
+
aline.type.must_equal :leader
|
17
|
+
aline.value.must_equal ' nam a22003011 4500'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "parses control fields" do
|
21
|
+
aline = MARC::AlephSequential::ASLine.new(@c1, 1)
|
22
|
+
aline.tag.must_equal '008'
|
23
|
+
aline.value.must_equal '880715r19701918enk b |00100 eng '
|
24
|
+
end
|
25
|
+
|
26
|
+
it "parses datafield basics" do
|
27
|
+
aline = MARC::AlephSequential::ASLine.new(@d1, 1)
|
28
|
+
aline.tag.must_equal '100'
|
29
|
+
aline.ind1.must_equal '1'
|
30
|
+
aline.ind2.must_equal ' '
|
31
|
+
end
|
32
|
+
|
33
|
+
it "parses subfields" do
|
34
|
+
aline = MARC::AlephSequential::ASLine.new(@d1, 1)
|
35
|
+
subfields = aline.parse_string_into_subfields(aline.value)
|
36
|
+
subfields[0].code.must_equal 'a'
|
37
|
+
subfields[1].code.must_equal 'd'
|
38
|
+
subfields[0].value.must_equal 'Clark, Albert Curtis,'
|
39
|
+
subfields[1].value.must_equal '1859-1937.'
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|