marc_alephsequential 1.0.0 → 2.0.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 +4 -4
- data/ChangeLog.md +15 -0
- data/README.md +8 -10
- data/lib/marc_alephsequential/reader.rb +27 -2
- data/lib/marc_alephsequential/version.rb +1 -1
- data/spec/reader_spec.rb +5 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c21cb8f33a3b2a1275e1c1fe4cbab9124105532e
|
4
|
+
data.tar.gz: 1679f8be5ceb7c577c9323a542237c533627ccd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9507f291bea0e23e0edf170c8aa1d9a7656da0bc8e74206d7182d52854b6420ab6058d45e7622b56f53723f097e988c1572eef5369c15612d77f143bb7cbf194
|
7
|
+
data.tar.gz: eca9f90589c7f5caef2fd23837d2f2af390a56fdc3d26b57c030477a10f6047e9f97034197ca75744ea0b603c0c820bf2ba183c988b65976a737ee5ab1bc25d3
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
### 2.0.0 /
|
2
|
+
|
3
|
+
Change the way MARC::AlephSequential::Reader deals with errors when
|
4
|
+
producing a record for `#each`. Instead of throwing an error (and aborting
|
5
|
+
the loop whether you wanted to or not, since there's no way to catch
|
6
|
+
the error in a provided block), it will now return a
|
7
|
+
MARC::AlephSequential::ErrorRecord `er` with a method `er.error` holding
|
8
|
+
the error.
|
9
|
+
|
10
|
+
This should affect almost no one.
|
11
|
+
|
12
|
+
### 1.0.0
|
13
|
+
|
14
|
+
First 1.0 release. No major changes.
|
15
|
+
|
1
16
|
### 0.1.1 / 2013-10-23
|
2
17
|
|
3
18
|
* Fixed bad call to respond_to in intializer
|
data/README.md
CHANGED
@@ -20,16 +20,14 @@ A [ruby-marc](https://github.com/ruby-marc/ruby-marc) reader for MARC files in t
|
|
20
20
|
reader = MARC::AlephSequential::Reader.new('myfile.seq.gz') # automatically notice the .gz and behave!
|
21
21
|
|
22
22
|
reader.log = log # optional. Set up a logger; otherwise, a default logger will be used
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
rescue => e
|
32
|
-
log.error "Other error of some sort. quitting. #{e.message}"
|
23
|
+
|
24
|
+
reader.each do |r|
|
25
|
+
if MARC::AlephSequential::ErrorRecord === r
|
26
|
+
e = r.error
|
27
|
+
log.error "Error while parsing record #{e.record_id} at/near #{e.line_number}: #{e.message}"
|
28
|
+
next
|
29
|
+
end
|
30
|
+
doStuffWithTheRecord(r)
|
33
31
|
end
|
34
32
|
|
35
33
|
```
|
@@ -7,6 +7,22 @@ require 'marc_alephsequential/log'
|
|
7
7
|
module MARC
|
8
8
|
module AlephSequential
|
9
9
|
|
10
|
+
# We need an empty record to signal an error condition that might
|
11
|
+
# occur within #each (e.g, the record has no leader). Raising the
|
12
|
+
# error will abort any #each loop without giving the user a chance
|
13
|
+
# to catch is (because by the time the block is run, the error has
|
14
|
+
# already been thrown). See a simplified example of this problem at
|
15
|
+
# https://gist.github.com/billdueber/6d501f730c79f6a74498
|
16
|
+
|
17
|
+
|
18
|
+
class ErrorRecord < MARC::Record
|
19
|
+
attr_accessor :error
|
20
|
+
def initialize(error)
|
21
|
+
super()
|
22
|
+
self.error = error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
10
26
|
class Reader
|
11
27
|
|
12
28
|
include Enumerable
|
@@ -30,7 +46,11 @@ module MARC
|
|
30
46
|
while @areader.has_next?
|
31
47
|
nextid = @areader.peek.id
|
32
48
|
if nextid != @current_id && @areader.peek.valid_id?
|
33
|
-
|
49
|
+
begin
|
50
|
+
yield agroup.to_record unless agroup.empty?
|
51
|
+
rescue RuntimeError => e
|
52
|
+
yield ErrorRecord.new(e)
|
53
|
+
end
|
34
54
|
agroup = ASLineGroup.new
|
35
55
|
@current_id = nextid
|
36
56
|
else
|
@@ -38,7 +58,12 @@ module MARC
|
|
38
58
|
end
|
39
59
|
end
|
40
60
|
# yield whatever is left, unless there's nothing left
|
41
|
-
|
61
|
+
begin
|
62
|
+
yield agroup.to_record unless agroup.empty?
|
63
|
+
rescue RuntimeError => e
|
64
|
+
yield ErrorRecord.new(e)
|
65
|
+
end
|
66
|
+
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
data/spec/reader_spec.rb
CHANGED
@@ -33,13 +33,11 @@ describe 'Reader' do
|
|
33
33
|
|
34
34
|
it "yells when there's no leader" do
|
35
35
|
error = nil
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
error.wont_be_nil
|
42
|
-
error.message.must_match /leader/
|
36
|
+
r = MARC::AlephSequential::Reader.new(@noleader).first
|
37
|
+
r.must_be_kind_of MARC::AlephSequential::ErrorRecord
|
38
|
+
r.must_respond_to :error
|
39
|
+
r.error.wont_be_nil
|
40
|
+
r.error.message.must_match /leader/
|
43
41
|
end
|
44
42
|
|
45
43
|
it "deals ok with embedded newline" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marc_alephsequential
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Dueber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: marc
|