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.
@@ -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,4 @@
1
+ module MarcAlephsequential
2
+ # marc_alephsequential version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,9 @@
1
+ require 'marc'
2
+ require 'marc_alephsequential/version'
3
+ require 'marc_alephsequential/error'
4
+ require 'marc_alephsequential/reader'
5
+
6
+
7
+ # Need to allow FMT tags as control tags
8
+
9
+ MARC::ControlField.control_tags << 'FMT'
@@ -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
@@ -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
+