Skip to content

Commit

Permalink
Fixed the serializers to not throw exceptions if indicators are set t…
Browse files Browse the repository at this point in the history
…o nil (instead throw a warning).

git-svn-id: http://marc.rubyforge.org/svn/trunk@917 4dc5e89f-90f6-0310-ab54-a6a856e7c30e
  • Loading branch information
rsinger committed Dec 17, 2009
1 parent b1a6b3c commit 0063b0e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rakefile
@@ -1,4 +1,4 @@
RUBY_MARC_VERSION = '0.3.1'
RUBY_MARC_VERSION = '0.3.2'

require 'rubygems'
require 'rake'
Expand Down
3 changes: 2 additions & 1 deletion lib/marc/writer.rb
Expand Up @@ -44,7 +44,8 @@ def self.encode(record)
# encode the field
field_data = ''
if field.class == MARC::DataField
field_data = field.indicator1 + field.indicator2
warn("Warn: Missing indicator") unless field.indicator1 && field.indicator2
field_data = (field.indicator1 || "z") + (field.indicator2 || "z")
for s in field.subfields
field_data += SUBFIELD_INDICATOR + s.code + s.value
end
Expand Down
4 changes: 2 additions & 2 deletions lib/marc/xmlwriter.rb
Expand Up @@ -101,13 +101,13 @@ def self.encode(record, opts={})

# If marc is leniently parsed, we may have some dirty data; using
# the 'z' ind1 value should help us locate these later to fix
if (field.indicator1.match(singleChar) == nil)
if field.indicator1.nil? || (field.indicator1.match(singleChar) == nil)
field.indicator1 = 'z'
end

# If marc is leniently parsed, we may have some dirty data; using
# the 'z' ind2 value should help us locate these later to fix
if (field.indicator2.match(singleChar) == nil)
if field.indicator2.nil? || (field.indicator2.match(singleChar) == nil)
field.indicator2 = 'z'
end

Expand Down
8 changes: 8 additions & 0 deletions test/tc_writer.rb
Expand Up @@ -19,6 +19,14 @@ def test_writer
# cleanup
File.unlink('test/writer.dat')
end

def test_forgiving_writer
marc = "00305cam a2200133 a 4500001000700000003000900007005001700016008004100033008004100074035002500115245001700140909001000157909000400167\036635145\036UK-BiLMS\03620060329173705.0\036s1982iieng6 000 0 eng||\036060116|||||||||xxk eng||\036 \037a(UK-BiLMS)M0017366ZW\03600\037aTest record.\036 \037aa\037b\037c\036\037b0\036\035\000"
rec = MARC::Record.new_from_marc(marc)
assert_nothing_raised do
rec.to_marc
end
end

def test_ampersand
end
Expand Down

0 comments on commit 0063b0e

Please sign in to comment.