marc 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/marc.rb +2 -2
- data/lib/marc/{control.rb → controlfield.rb} +15 -4
- data/lib/marc/{field.rb → datafield.rb} +6 -7
- data/lib/marc/reader.rb +3 -3
- data/lib/marc/subfield.rb +1 -1
- data/lib/marc/writer.rb +2 -2
- data/lib/marc/xmlreader.rb +3 -3
- data/lib/marc/xmlwriter.rb +19 -19
- data/test/foo.xml +1 -0
- data/test/tc_controlfield.rb +25 -0
- data/test/tc_datafield.rb +62 -0
- data/test/tc_record.rb +8 -8
- data/test/tc_subfield.rb +5 -5
- data/test/tc_writer.rb +1 -1
- data/test/tc_xmlreader.rb +5 -5
- data/test/ts_marc.rb +2 -1
- metadata +40 -33
- data/test/tc_field.rb +0 -81
data/lib/marc.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module MARC
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
3
|
+
# MARC records contain control fields, each of which has a
|
4
|
+
# tag and value. Tags for control fields must be in the
|
5
|
+
# 001-009 range.
|
6
6
|
|
7
|
-
class
|
7
|
+
class ControlField
|
8
8
|
|
9
9
|
# the tag value (007, 008, etc)
|
10
10
|
attr_accessor :tag
|
@@ -23,6 +23,17 @@ module MARC
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
# Two control fields are equal if their tags and values are equal.
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
if @tag != other.tag
|
30
|
+
return false
|
31
|
+
elsif @value != other.value
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
|
26
37
|
def to_s
|
27
38
|
return "#{tag} #{value}"
|
28
39
|
end
|
@@ -3,12 +3,11 @@ require 'marc/record'
|
|
3
3
|
|
4
4
|
module MARC
|
5
5
|
|
6
|
-
# MARC records
|
7
|
-
# indicators and subfields.
|
8
|
-
#
|
9
|
-
# indicators.
|
6
|
+
# MARC records contain data fields, each of which has a tag,
|
7
|
+
# indicators and subfields. Tags for data fields must be in
|
8
|
+
# the range 010-999.
|
10
9
|
|
11
|
-
class
|
10
|
+
class DataField
|
12
11
|
include Enumerable
|
13
12
|
|
14
13
|
# The tag for the field
|
@@ -28,14 +27,14 @@ module MARC
|
|
28
27
|
# Subfields are passed in as comma separated list of
|
29
28
|
# MARC::Subfield objects,
|
30
29
|
#
|
31
|
-
# field = MARC::
|
30
|
+
# field = MARC::DataField.new('245','0','0',
|
32
31
|
# MARC::Subfield.new('a', 'Consilience :'),
|
33
32
|
# MARC::Subfield.new('b', 'the unity of knowledge ',
|
34
33
|
# MARC::Subfield.new('c', 'by Edward O. Wilson.'))
|
35
34
|
#
|
36
35
|
# or using a shorthand:
|
37
36
|
#
|
38
|
-
# field = MARC::
|
37
|
+
# field = MARC::DataField.new('245','0','0',
|
39
38
|
# ['a', 'Consilience :'],['b','the unity of knowledge ',
|
40
39
|
# ['c', 'by Edward O. Wilson.'] )
|
41
40
|
|
data/lib/marc/reader.rb
CHANGED
@@ -103,11 +103,11 @@ module MARC
|
|
103
103
|
# remove end of field
|
104
104
|
field_data.delete!(END_OF_FIELD)
|
105
105
|
|
106
|
-
# add a control field or
|
106
|
+
# add a control field or data field
|
107
107
|
if tag < '010'
|
108
|
-
record.append(MARC::
|
108
|
+
record.append(MARC::ControlField.new(tag,field_data))
|
109
109
|
else
|
110
|
-
field = MARC::
|
110
|
+
field = MARC::DataField.new(tag)
|
111
111
|
|
112
112
|
# get all subfields
|
113
113
|
subfields = field_data.split(SUBFIELD_INDICATOR)
|
data/lib/marc/subfield.rb
CHANGED
data/lib/marc/writer.rb
CHANGED
@@ -43,12 +43,12 @@ module MARC
|
|
43
43
|
|
44
44
|
# encode the field
|
45
45
|
field_data = ''
|
46
|
-
if field.class == MARC::
|
46
|
+
if field.class == MARC::DataField
|
47
47
|
field_data = field.indicator1 + field.indicator2
|
48
48
|
for s in field.subfields
|
49
49
|
field_data += SUBFIELD_INDICATOR + s.code + s.value
|
50
50
|
end
|
51
|
-
elsif field.class == MARC::
|
51
|
+
elsif field.class == MARC::ControlField
|
52
52
|
field_data = field.value
|
53
53
|
end
|
54
54
|
field_data += END_OF_FIELD
|
data/lib/marc/xmlreader.rb
CHANGED
@@ -24,7 +24,7 @@ module MARC
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def strip_ns(str)
|
27
|
-
return str.sub
|
27
|
+
return str.sub(/^.*:/, '')
|
28
28
|
end
|
29
29
|
|
30
30
|
# will accept parse events until a record has been built up
|
@@ -50,10 +50,10 @@ module MARC
|
|
50
50
|
case strip_ns(event[0])
|
51
51
|
when 'controlfield'
|
52
52
|
text = ''
|
53
|
-
control_field = MARC::
|
53
|
+
control_field = MARC::ControlField.new(attrs['tag'])
|
54
54
|
when 'datafield'
|
55
55
|
text = ''
|
56
|
-
data_field = MARC::
|
56
|
+
data_field = MARC::DataField.new(attrs['tag'], attrs['ind1'],
|
57
57
|
attrs['ind2'])
|
58
58
|
when 'subfield'
|
59
59
|
text = ''
|
data/lib/marc/xmlwriter.rb
CHANGED
@@ -20,9 +20,9 @@ module MARC
|
|
20
20
|
|
21
21
|
@fh.write("<?xml version='1.0'?>")
|
22
22
|
|
23
|
-
@fh.write("<
|
24
|
-
|
25
|
-
|
23
|
+
@fh.write("<collection xmlns='" + MARC_NS + "' " +
|
24
|
+
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
|
25
|
+
"xsi:schemaLocation='" + MARC_NS + " " + MARC_XSD + "'>")
|
26
26
|
end
|
27
27
|
|
28
28
|
|
@@ -36,7 +36,7 @@ module MARC
|
|
36
36
|
# close underlying filehandle
|
37
37
|
|
38
38
|
def close
|
39
|
-
@fh.write("</
|
39
|
+
@fh.write("</collection>")
|
40
40
|
@fh.close
|
41
41
|
end
|
42
42
|
|
@@ -45,38 +45,38 @@ module MARC
|
|
45
45
|
# and returns a REXML::Document for the XML serialization
|
46
46
|
|
47
47
|
def self.encode(record)
|
48
|
-
root = "<
|
48
|
+
root = "<record/>"
|
49
49
|
doc = REXML::Document.new root
|
50
50
|
|
51
51
|
# MARCXML is particular about this; ILSes aren't
|
52
52
|
record.leader[20..24] = "4500"
|
53
53
|
|
54
|
-
leader = REXML::Element.new "
|
54
|
+
leader = REXML::Element.new "leader"
|
55
55
|
leader.add_text record.leader
|
56
56
|
doc.root.add_element leader
|
57
57
|
|
58
58
|
for field in record.fields
|
59
|
-
if field.class == MARC::
|
60
|
-
|
61
|
-
|
59
|
+
if field.class == MARC::DataField
|
60
|
+
datafield_elem = REXML::Element.new "datafield"
|
61
|
+
datafield_elem.add_attributes({
|
62
62
|
"tag"=>field.tag,
|
63
63
|
"ind1"=>field.indicator1,
|
64
64
|
"ind2"=>field.indicator2
|
65
65
|
})
|
66
66
|
|
67
67
|
for subfield in field.subfields
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
subfield_element = REXML::Element.new "subfield"
|
69
|
+
subfield_element.add_attribute("code", subfield.code)
|
70
|
+
subfield_element.add_text subfield.value
|
71
|
+
datafield_elem.add_element subfield_element
|
72
72
|
end
|
73
73
|
|
74
|
-
doc.root.add_element
|
75
|
-
elsif field.class == MARC::
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
doc.root.add_element
|
74
|
+
doc.root.add_element datafield_elem
|
75
|
+
elsif field.class == MARC::ControlField
|
76
|
+
control_element = REXML::Element.new "controlfield"
|
77
|
+
control_element.add_attribute("tag", field.tag)
|
78
|
+
control_element.add_text field.value
|
79
|
+
doc.root.add_element control_element
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
data/test/foo.xml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version='1.0'?><collection xmlns='http://www.loc.gov/MARC21/slim' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd'><record><leader>00925njm 22002777a 4500</leader><controlfield tag='007'>sdubumennmplu</controlfield><datafield tag='245' ind1='0' ind2='4'><subfield code='a'>The Great Ray Charles</subfield><subfield code='h'>[sound recording].</subfield></datafield></record></collection>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
class TestField < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_control
|
7
|
+
control = MARC::ControlField.new('005', 'foobarbaz')
|
8
|
+
assert_equal(control.to_s, '005 foobarbaz')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_field_as_control
|
12
|
+
assert_raise(MARC::Exception) do
|
13
|
+
# can't have a field with a tag < 010
|
14
|
+
field = MARC::DataField.new('007')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_control_as_field
|
19
|
+
assert_raise(MARC::Exception) do
|
20
|
+
# can't have a control with a tag > 009
|
21
|
+
f = MARC::ControlField.new('245')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
class TestField < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_tag
|
7
|
+
f1 = MARC::DataField.new('100')
|
8
|
+
assert_equal('100', f1.tag)
|
9
|
+
f2 = MARC::DataField.new(tag='100')
|
10
|
+
assert_equal('100', f2.tag)
|
11
|
+
assert_equal(f1, f2)
|
12
|
+
f3 = MARC::DataField.new('245')
|
13
|
+
assert_not_equal(f1, f3)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_indicators
|
17
|
+
f1 = MARC::DataField.new('100', '0', '1')
|
18
|
+
assert_equal('0', f1.indicator1)
|
19
|
+
assert_equal('1', f1.indicator2)
|
20
|
+
f2 = MARC::DataField.new(tag='100',i1='0',i2='1')
|
21
|
+
assert_equal('0', f2.indicator1)
|
22
|
+
assert_equal('1', f2.indicator2)
|
23
|
+
assert_equal(f1, f2)
|
24
|
+
f3 = MARC::DataField.new(tag='100', i1='1', i2='1')
|
25
|
+
assert_not_equal(f1, f3)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_subfields
|
29
|
+
f1 = MARC::DataField.new('100', '0', '1',
|
30
|
+
MARC::Subfield.new('a', 'Foo'),
|
31
|
+
MARC::Subfield.new('b', 'Bar') )
|
32
|
+
assert_equal("100 01 $a Foo $b Bar ", f1.to_s)
|
33
|
+
f2 = MARC::DataField.new('100', '0', '1',
|
34
|
+
MARC::Subfield.new('a', 'Foo'),
|
35
|
+
MARC::Subfield.new('b', 'Bar') )
|
36
|
+
assert_equal(f1,f2)
|
37
|
+
f3 = MARC::DataField.new('100', '0', '1',
|
38
|
+
MARC::Subfield.new('a', 'Foo'),
|
39
|
+
MARC::Subfield.new('b', 'Bez') )
|
40
|
+
assert_not_equal(f1,f3)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_subfield_shorthand
|
44
|
+
f = MARC::DataField.new('100', '0', '1', ['a', 'Foo'], ['b', 'Bar'])
|
45
|
+
assert_equal('100 01 $a Foo $b Bar ', f.to_s)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def test_iterator
|
50
|
+
field = MARC::DataField.new('100', '0', '1', ['a', 'Foo'],['b', 'Bar'],
|
51
|
+
['a', 'Bez'])
|
52
|
+
count = 0
|
53
|
+
field.each {|x| count += 1}
|
54
|
+
assert_equal(count,3)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lookup_shorthand
|
58
|
+
f = MARC::DataField.new('100', '0', '1', ['a', 'Foo'], ['b', 'Bar'])
|
59
|
+
assert_equal(f['b'], 'Bar')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/test/tc_record.rb
CHANGED
@@ -24,26 +24,26 @@ class TestRecord < Test::Unit::TestCase
|
|
24
24
|
raw = IO.read('test/one.dat')
|
25
25
|
r = MARC::Record::new_from_marc(raw)
|
26
26
|
assert_equal(r.class, MARC::Record)
|
27
|
-
assert_equal(r.leader,'00755cam 22002414a 4500')
|
27
|
+
assert_equal(r.leader, '00755cam 22002414a 4500')
|
28
28
|
assert_equal(r.fields.length(), 18)
|
29
29
|
assert_equal(r.find {|f| f.tag == '245'}.to_s,
|
30
|
-
'245 10 $
|
30
|
+
'245 10 $a ActivePerl with ASP and ADO / $c Tobias Martinsson. ')
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_decode_forgiving
|
34
34
|
raw = IO.read('test/one.dat')
|
35
35
|
r = MARC::Record::new_from_marc(raw, :forgiving => true)
|
36
36
|
assert_equal(r.class, MARC::Record)
|
37
|
-
assert_equal(r.leader,'00755cam 22002414a 4500')
|
37
|
+
assert_equal(r.leader, '00755cam 22002414a 4500')
|
38
38
|
assert_equal(r.fields.length(), 18)
|
39
39
|
assert_equal(r.find {|f| f.tag == '245'}.to_s,
|
40
|
-
'245 10 $
|
40
|
+
'245 10 $a ActivePerl with ASP and ADO / $c Tobias Martinsson. ')
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_encode
|
44
44
|
r1 = MARC::Record.new()
|
45
|
-
r1.append(MARC::
|
46
|
-
r1.append(MARC::
|
45
|
+
r1.append(MARC::DataField.new('100', '2', '0', ['a', 'Thomas, Dave']))
|
46
|
+
r1.append(MARC::DataField.new('245', '0', '0', ['a', 'Pragmatic Programmer']))
|
47
47
|
raw = r1.to_marc()
|
48
48
|
r2 = MARC::Record::new_from_marc(raw)
|
49
49
|
assert_equal(r1, r2)
|
@@ -56,8 +56,8 @@ class TestRecord < Test::Unit::TestCase
|
|
56
56
|
|
57
57
|
def get_record
|
58
58
|
r = MARC::Record.new()
|
59
|
-
r.append(MARC::
|
60
|
-
r.append(MARC::
|
59
|
+
r.append(MARC::DataField.new('100', '2', '0', ['a', 'Thomas, Dave']))
|
60
|
+
r.append(MARC::DataField.new('245', '0', '4', ['The Pragmatic Programmer']))
|
61
61
|
return r
|
62
62
|
end
|
63
63
|
|
data/test/tc_subfield.rb
CHANGED
@@ -4,14 +4,14 @@ require 'marc/subfield'
|
|
4
4
|
class SubfieldTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def test_ok
|
7
|
-
s = MARC::Subfield.new('a','foo')
|
8
|
-
assert_equal(s.code,'a')
|
9
|
-
assert_equal(s.value,'foo')
|
7
|
+
s = MARC::Subfield.new('a', 'foo')
|
8
|
+
assert_equal(s.code, 'a')
|
9
|
+
assert_equal(s.value, 'foo')
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_equals
|
13
|
-
s1 =MARC::Subfield.new('a','foo')
|
14
|
-
s2 =MARC::Subfield.new('a','foo')
|
13
|
+
s1 =MARC::Subfield.new('a', 'foo')
|
14
|
+
s2 =MARC::Subfield.new('a', 'foo')
|
15
15
|
assert_equal(s1,s2)
|
16
16
|
end
|
17
17
|
|
data/test/tc_writer.rb
CHANGED
@@ -6,7 +6,7 @@ class WriterTest < Test::Unit::TestCase
|
|
6
6
|
def test_writer()
|
7
7
|
writer = MARC::Writer.new('test/writer.dat')
|
8
8
|
record = MARC::Record.new()
|
9
|
-
record.append(MARC::
|
9
|
+
record.append(MARC::DataField.new('245', '0', '1', ['a', 'foo']))
|
10
10
|
writer.write(record)
|
11
11
|
writer.close()
|
12
12
|
|
data/test/tc_xmlreader.rb
CHANGED
@@ -3,7 +3,7 @@ require 'marc'
|
|
3
3
|
|
4
4
|
class XMLReaderTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
def
|
6
|
+
def otest_batch
|
7
7
|
reader = MARC::XMLReader.new('test/batch.xml')
|
8
8
|
count = 0
|
9
9
|
for record in reader
|
@@ -16,9 +16,9 @@ class XMLReaderTest < Test::Unit::TestCase
|
|
16
16
|
def test_read_write
|
17
17
|
record1 = MARC::Record.new
|
18
18
|
record1.leader = '00925njm 22002777a 4500'
|
19
|
-
record1.append MARC::
|
20
|
-
record1.append MARC::
|
21
|
-
['a','The Great Ray Charles'], ['h', '[sound recording].'])
|
19
|
+
record1.append MARC::ControlField.new('007', 'sdubumennmplu')
|
20
|
+
record1.append MARC::DataField.new('245', '0', '4',
|
21
|
+
['a', 'The Great Ray Charles'], ['h', '[sound recording].'])
|
22
22
|
|
23
23
|
writer = MARC::XMLWriter.new('test/foo.xml')
|
24
24
|
writer.write(record1)
|
@@ -28,7 +28,7 @@ class XMLReaderTest < Test::Unit::TestCase
|
|
28
28
|
record2 = reader.entries[0]
|
29
29
|
assert_equal(record1, record2)
|
30
30
|
|
31
|
-
File.unlink('test/foo.xml')
|
31
|
+
#File.unlink('test/foo.xml')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
data/test/ts_marc.rb
CHANGED
metadata
CHANGED
@@ -3,11 +3,11 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: marc
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2006-01-
|
6
|
+
version: 0.0.8
|
7
|
+
date: 2006-01-16 00:00:00 -05:00
|
8
8
|
summary: A ruby library for working with Machine Readable Cataloging
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: ehs@pobox.com
|
12
12
|
homepage: http://www.textualize.com/ruby_marc
|
13
13
|
rubyforge_project:
|
@@ -18,45 +18,52 @@ bindir: bin
|
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
29
28
|
authors:
|
30
|
-
|
29
|
+
- Ed Summers
|
31
30
|
files:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
31
|
+
- lib/marc
|
32
|
+
- lib/marc.rb
|
33
|
+
- lib/marc/writer.rb
|
34
|
+
- lib/marc/subfield.rb
|
35
|
+
- lib/marc/datafield.rb
|
36
|
+
- lib/marc/record.rb
|
37
|
+
- lib/marc/constants.rb
|
38
|
+
- lib/marc/xmlreader.rb
|
39
|
+
- lib/marc/xmlwriter.rb
|
40
|
+
- lib/marc/exception.rb
|
41
|
+
- lib/marc/controlfield.rb
|
42
|
+
- lib/marc/reader.rb
|
43
|
+
- test/batch.dat
|
44
|
+
- test/batch.xml
|
45
|
+
- test/tc_datafield.rb
|
46
|
+
- test/tc_reader.rb
|
47
|
+
- test/foo.xml
|
48
|
+
- test/tc_writer.rb
|
49
|
+
- test/tc_controlfield.rb
|
50
|
+
- test/tc_subfield.rb
|
51
|
+
- test/one.dat
|
52
|
+
- test/tc_xmlreader.rb
|
53
|
+
- test/tc_xmlwriter.rb
|
54
|
+
- test/tc_record.rb
|
55
|
+
- test/ts_marc.rb
|
55
56
|
test_files:
|
56
|
-
|
57
|
+
- test/ts_marc.rb
|
57
58
|
rdoc_options: []
|
59
|
+
|
58
60
|
extra_rdoc_files: []
|
61
|
+
|
59
62
|
executables: []
|
63
|
+
|
60
64
|
extensions: []
|
65
|
+
|
61
66
|
requirements: []
|
62
|
-
|
67
|
+
|
68
|
+
dependencies: []
|
69
|
+
|
data/test/tc_field.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'marc'
|
3
|
-
|
4
|
-
class TestField < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_tag
|
7
|
-
f1 = MARC::Field.new('100')
|
8
|
-
assert_equal('100', f1.tag)
|
9
|
-
f2 = MARC::Field.new(tag='100')
|
10
|
-
assert_equal('100', f2.tag)
|
11
|
-
assert_equal(f1, f2)
|
12
|
-
f3 = MARC::Field.new('245')
|
13
|
-
assert_not_equal(f1, f3)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_indicators
|
17
|
-
f1 = MARC::Field.new('100', '0', '1')
|
18
|
-
assert_equal('0', f1.indicator1)
|
19
|
-
assert_equal('1', f1.indicator2)
|
20
|
-
f2 = MARC::Field.new(tag='100',i1='0',i2='1')
|
21
|
-
assert_equal('0', f2.indicator1)
|
22
|
-
assert_equal('1', f2.indicator2)
|
23
|
-
assert_equal(f1, f2)
|
24
|
-
f3 = MARC::Field.new(tag='100', i1='1', i2='1')
|
25
|
-
assert_not_equal(f1, f3)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_subfields
|
29
|
-
f1 = MARC::Field.new('100', '0', '1',
|
30
|
-
MARC::Subfield.new('a', 'Foo'),
|
31
|
-
MARC::Subfield.new('b', 'Bar') )
|
32
|
-
assert_equal("100 01 $aFoo$bBar", f1.to_s)
|
33
|
-
f2 = MARC::Field.new('100', '0', '1',
|
34
|
-
MARC::Subfield.new('a', 'Foo'),
|
35
|
-
MARC::Subfield.new('b', 'Bar') )
|
36
|
-
assert_equal(f1,f2)
|
37
|
-
f3 = MARC::Field.new('100', '0', '1',
|
38
|
-
MARC::Subfield.new('a', 'Foo'),
|
39
|
-
MARC::Subfield.new('b', 'Bez') )
|
40
|
-
assert_not_equal(f1,f3)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_subfield_shorthand
|
44
|
-
f = MARC::Field.new('100', '0', '1', ['a', 'Foo'], ['b', 'Bar'])
|
45
|
-
assert_equal('100 01 $aFoo$bBar', f.to_s)
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
def test_iterator
|
50
|
-
field = MARC::Field.new('100','0','1', ['a', 'Foo'],['b', 'Bar'],
|
51
|
-
['a', 'Bez'])
|
52
|
-
count = 0
|
53
|
-
field.each {|x| count += 1}
|
54
|
-
assert_equal(count,3)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_lookup_shorthand
|
58
|
-
f = MARC::Field.new('100', '0', '1', ['a', 'Foo'], ['b', 'Bar'])
|
59
|
-
assert_equal(f['b'], 'Bar')
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_control
|
63
|
-
control = MARC::Control.new('005','foobarbaz')
|
64
|
-
assert_equal(control.to_s,'005 foobarbaz')
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_field_as_control
|
68
|
-
assert_raise(MARC::Exception) do
|
69
|
-
# can't have a field with a tag < 010
|
70
|
-
field = MARC::Field.new('007')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_control_as_field
|
75
|
-
assert_raise(MARC::Exception) do
|
76
|
-
# can't have a control with a tag > 009
|
77
|
-
f = MARC::Control.new('245')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|