eadcodec 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +12 -5
- data/lib/eadcodec.rb +76 -1
- data/lib/elements/accessrestrict.rb +12 -0
- data/lib/elements/accruals.rb +11 -0
- data/lib/elements/acqinfo.rb +12 -0
- data/lib/elements/altformavail.rb +12 -0
- data/lib/elements/appraisal.rb +11 -0
- data/lib/elements/archdesc.rb +32 -0
- data/lib/elements/arrangement.rb +11 -0
- data/lib/elements/bibliography.rb +12 -0
- data/lib/elements/bioghist.rb +11 -0
- data/lib/elements/c.rb +65 -0
- data/lib/elements/chronitem.rb +12 -0
- data/lib/elements/chronlist.rb +12 -0
- data/lib/elements/container.rb +13 -0
- data/lib/elements/controlaccess.rb +10 -0
- data/lib/elements/creation.rb +4 -0
- data/lib/elements/custodhist.rb +11 -0
- data/lib/elements/date.rb +14 -0
- data/lib/elements/defitem.rb +10 -0
- data/lib/elements/description.rb +10 -0
- data/lib/elements/dimensions.rb +13 -0
- data/lib/elements/dsc.rb +21 -0
- data/lib/elements/ead.rb +39 -0
- data/lib/elements/eadheader.rb +28 -0
- data/lib/elements/event.rb +9 -0
- data/lib/elements/extent.rb +13 -0
- data/lib/elements/filedesc.rb +13 -0
- data/lib/elements/fileplan.rb +10 -0
- data/lib/elements/geogname.rb +16 -0
- data/lib/elements/head.rb +11 -0
- data/lib/elements/id.rb +12 -0
- data/lib/elements/item.rb +9 -0
- data/lib/elements/label.rb +9 -0
- data/lib/elements/langmaterial.rb +12 -0
- data/lib/elements/language.rb +20 -0
- data/lib/elements/list.rb +13 -0
- data/lib/elements/materialspec.rb +13 -0
- data/lib/elements/name.rb +15 -0
- data/lib/elements/note.rb +15 -0
- data/lib/elements/odd.rb +13 -0
- data/lib/elements/originalsloc.rb +12 -0
- data/lib/elements/origination.rb +12 -0
- data/lib/elements/otherfindaid.rb +11 -0
- data/lib/elements/p.rb +10 -0
- data/lib/elements/physdesc.rb +14 -0
- data/lib/elements/physfacet.rb +16 -0
- data/lib/elements/physloc.rb +14 -0
- data/lib/elements/phystech.rb +11 -0
- data/lib/elements/processinfo.rb +11 -0
- data/lib/elements/profiledesc.rb +10 -0
- data/lib/elements/relatedmaterial.rb +12 -0
- data/lib/elements/repository.rb +12 -0
- data/lib/elements/scopecontent.rb +12 -0
- data/lib/elements/subtitle.rb +4 -0
- data/lib/elements/titlestmt.rb +12 -0
- data/lib/elements/unitdate.rb +7 -0
- data/lib/elements/unitid.rb +16 -0
- data/lib/elements/unittitle.rb +13 -0
- data/lib/elements/userestrict.rb +12 -0
- data/test/{TestEADDescription.rb → description_test.rb} +27 -26
- data/test/{TestEADDocument.rb → document_test.rb} +2 -2
- data/test/level_test.rb +75 -0
- data/test/note_test.rb +36 -0
- data/test/partial_export_test.rb +63 -0
- data/test/phystech_test.rb +45 -0
- data/test/scopecontent_test.rb +41 -0
- data/test/{TestEADSubordinates.rb → subordinates_test.rb} +7 -8
- data/test/{TestEADSubtitle.rb → subtitle_test.rb} +5 -6
- data/test/test_helper.rb +45 -0
- data/test/xmlsoparser_test.rb +119 -0
- metadata +72 -50
- data/lib/EAD.rb +0 -229
- data/lib/EADAcqInfo.rb +0 -13
- data/lib/EADAltFormAvail.rb +0 -13
- data/lib/EADAppraisal.rb +0 -12
- data/lib/EADArrangement.rb +0 -12
- data/lib/EADBiogHist.rb +0 -10
- data/lib/EADChronList.rb +0 -27
- data/lib/EADContainer.rb +0 -15
- data/lib/EADControlAccess.rb +0 -12
- data/lib/EADCustodHist.rb +0 -12
- data/lib/EADDate.rb +0 -24
- data/lib/EADDescription.rb +0 -22
- data/lib/EADDimensions.rb +0 -15
- data/lib/EADDocument.rb +0 -106
- data/lib/EADEvent.rb +0 -11
- data/lib/EADExtent.rb +0 -15
- data/lib/EADFilePlan.rb +0 -12
- data/lib/EADGeogName.rb +0 -15
- data/lib/EADHeader.rb +0 -70
- data/lib/EADLabel.rb +0 -11
- data/lib/EADLang.rb +0 -42
- data/lib/EADLevel.rb +0 -73
- data/lib/EADList.rb +0 -36
- data/lib/EADMaterialSpec.rb +0 -14
- data/lib/EADName.rb +0 -17
- data/lib/EADNote.rb +0 -24
- data/lib/EADOtherFindAid.rb +0 -12
- data/lib/EADPhysFacet.rb +0 -17
- data/lib/EADPhysTech.rb +0 -16
- data/lib/EADProcessInfo.rb +0 -13
- data/lib/EADProfileDesc.rb +0 -17
- data/lib/EADRelatedMaterial.rb +0 -21
- data/lib/EADRepository.rb +0 -13
- data/lib/EADScopeContent.rb +0 -21
- data/lib/EADSubordinates.rb +0 -29
- data/lib/EADSubtitle.rb +0 -8
- data/test/TestEAD.rb +0 -50
- data/test/TestEADLevel.rb +0 -76
- data/test/TestEADNote.rb +0 -36
- data/test/TestEADPhysTech.rb +0 -44
- data/test/TestEADScopeContent.rb +0 -43
- data/test/TestPartialExport.rb +0 -61
- data/test/TestXMLStreamObjectParser.rb +0 -126
@@ -0,0 +1,20 @@
|
|
1
|
+
class Language < EADElement
|
2
|
+
elname "language"
|
3
|
+
|
4
|
+
xmlattr :altrender
|
5
|
+
xmlattr :audience
|
6
|
+
xmlattr :encodinganalog
|
7
|
+
xmlattr :id
|
8
|
+
xmlattr :langcode
|
9
|
+
xmlattr :scriptcode
|
10
|
+
|
11
|
+
xmlsubelements
|
12
|
+
|
13
|
+
def initialize(*values)
|
14
|
+
if values
|
15
|
+
values.each do |v|
|
16
|
+
self.subelements << v
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/elements/odd.rb
ADDED
data/lib/elements/p.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class PhysFacet < EADElement
|
2
|
+
include WithText
|
3
|
+
elname "physfacet"
|
4
|
+
|
5
|
+
xmlattr :altrender
|
6
|
+
xmlattr :audience
|
7
|
+
xmlattr :encodinganalog
|
8
|
+
xmlattr :id
|
9
|
+
xmlattr :label
|
10
|
+
xmlattr :rules
|
11
|
+
xmlattr :source
|
12
|
+
xmlattr :type
|
13
|
+
xmlattr :unit
|
14
|
+
|
15
|
+
xmlsubelements
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class UnitId < EADElement
|
2
|
+
include WithText
|
3
|
+
elname "unitid"
|
4
|
+
|
5
|
+
xmlattr :altrender
|
6
|
+
xmlattr :audience
|
7
|
+
xmlattr :countrycode
|
8
|
+
xmlattr :encodinganalog
|
9
|
+
xmlattr :id
|
10
|
+
xmlattr :identifier
|
11
|
+
xmlattr :label
|
12
|
+
xmlattr :repositorycode
|
13
|
+
xmlattr :type
|
14
|
+
|
15
|
+
xmlsubelements
|
16
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
|
-
class TestEADDescription <
|
3
|
+
class TestEADDescription < Test::Unit::TestCase
|
4
4
|
def initialize(*args)
|
5
5
|
super(*args)
|
6
6
|
|
@@ -20,20 +20,21 @@ class TestEADDescription < TestEAD
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_description
|
23
|
-
did =
|
24
|
-
did
|
25
|
-
did
|
26
|
-
did
|
27
|
-
did
|
28
|
-
did
|
29
|
-
did
|
30
|
-
did
|
23
|
+
did = EADCodec::Description.new
|
24
|
+
did << EADCodec::Head.new(@head)
|
25
|
+
did << EADCodec::Origination.new(@origination)
|
26
|
+
did << EADCodec::UnitTitle.new(@unittitle)
|
27
|
+
did << EADCodec::UnitId.new(@unitid)
|
28
|
+
did << EADCodec::Abstract.new(@abstract)
|
29
|
+
did << EADCodec::PhysDesc.new(@physdesc)
|
30
|
+
did << EADCodec::PhysLoc.new(@physloc)
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
ud = EADCodec::UnitDate.new(@unitdate)
|
33
|
+
ud.label = @unitdatelabel
|
34
|
+
ud.type = @unitdatetype
|
35
|
+
did << ud
|
36
|
+
|
37
|
+
@ead.archdesc << did
|
37
38
|
export
|
38
39
|
|
39
40
|
# Since we've added content it is now valid EAD
|
@@ -56,18 +57,18 @@ class TestEADDescription < TestEAD
|
|
56
57
|
|
57
58
|
def test_import_description
|
58
59
|
import
|
59
|
-
did = @ead.
|
60
|
+
did = @ead.archdesc[:did]
|
60
61
|
|
61
|
-
assert_equal(@head, did
|
62
|
-
assert_equal(@origination, did
|
63
|
-
assert_equal(@unittitle, did
|
64
|
-
assert_equal(@unitid, did
|
65
|
-
assert_equal(@abstract, did
|
66
|
-
assert_equal(@physdesc, did
|
67
|
-
assert_equal(@physloc, did
|
62
|
+
assert_equal(@head, did[:head].value)
|
63
|
+
assert_equal(@origination, did[:origination].value)
|
64
|
+
assert_equal(@unittitle, did[:unittitle].value)
|
65
|
+
assert_equal(@unitid, did[:unitid].value)
|
66
|
+
assert_equal(@abstract, did[:abstract].value)
|
67
|
+
assert_equal(@physdesc, did[:physdesc].value)
|
68
|
+
assert_equal(@physloc, did[:physloc].value)
|
68
69
|
|
69
|
-
assert_equal(@unitdate, did
|
70
|
-
assert_equal(@unitdatelabel, did
|
71
|
-
assert_equal(@unitdatetype, did
|
70
|
+
assert_equal(@unitdate, did[:unitdate].value)
|
71
|
+
assert_equal(@unitdatelabel, did[:unitdate].label)
|
72
|
+
assert_equal(@unitdatetype, did[:unitdate].type)
|
72
73
|
end
|
73
74
|
end
|
data/test/level_test.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestEADLevel < Test::Unit::TestCase
|
4
|
+
def initialize(*args)
|
5
|
+
super(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def export_doc(opt)
|
9
|
+
dsc = EADCodec::Subordinates.new
|
10
|
+
@ead.archdesc << dsc
|
11
|
+
|
12
|
+
c01 = EADCodec::Level.new
|
13
|
+
c01.set_unnumbered if opt == :unnumbered
|
14
|
+
c01 << EADCodec::Description.new
|
15
|
+
c01 << EADCodec::PhysTech.new
|
16
|
+
dsc << c01
|
17
|
+
|
18
|
+
c02 = EADCodec::Level.new
|
19
|
+
c01 << c02
|
20
|
+
|
21
|
+
c03 = EADCodec::Level.new
|
22
|
+
c02 << c03
|
23
|
+
|
24
|
+
@test_file = 'test_ead_level_'+opt.to_s+'.xml'
|
25
|
+
export @test_file
|
26
|
+
end
|
27
|
+
|
28
|
+
#def test_attrs
|
29
|
+
# export_doc(:numbered)
|
30
|
+
# element_exists("/ead/archdesc/dsc/c01", "Check that the level was added")
|
31
|
+
# element_exists("/ead/archdesc/dsc/c01/did", "Check that the description was added")
|
32
|
+
# element_exists("/ead/archdesc/dsc/c01/phystech", "Check that the phystech was added")
|
33
|
+
# element_exists("/ead/archdesc/dsc/c01/c02", "Check that the second level was added")
|
34
|
+
# element_exists("/ead/archdesc/dsc/c01/c02/c03", "Check that the third level was added")
|
35
|
+
#end
|
36
|
+
|
37
|
+
#def test_import
|
38
|
+
# export_doc(:numbered)
|
39
|
+
# import
|
40
|
+
# dsc = @ead.archdesc.find_first_named(:dsc)
|
41
|
+
#
|
42
|
+
# c01 = dsc.find_first_named(:c01)
|
43
|
+
# assert(c01, "Check that the level was imported")
|
44
|
+
# assert(c01.find_first_named(:did), "Check that the description was imported")
|
45
|
+
#
|
46
|
+
# c02 = c01.find_first_named(:c02)
|
47
|
+
# assert(c02, "Check that the second level was imported")
|
48
|
+
# assert(c02.find_first_named(:c03), "Check that the third level was imported")
|
49
|
+
#end
|
50
|
+
|
51
|
+
def test_attrs_unnumbered
|
52
|
+
@test_file = "test_ead_level_unnumbered.xml"
|
53
|
+
export_doc(:unnumbered)
|
54
|
+
export
|
55
|
+
element_exists("/ead/archdesc/dsc/c", "Check that the level was added")
|
56
|
+
element_exists("/ead/archdesc/dsc/c/did", "Check that the description was added")
|
57
|
+
element_exists("/ead/archdesc/dsc/c/phystech", "Check that the phystech was added")
|
58
|
+
element_exists("/ead/archdesc/dsc/c/c", "Check that the second level was added")
|
59
|
+
element_exists("/ead/archdesc/dsc/c/c/c", "Check that the third level was added")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_import_unnumbered
|
63
|
+
@test_file = "test_ead_level_unnumbered.xml"
|
64
|
+
export_doc(:unnumbered)
|
65
|
+
import
|
66
|
+
dsc = @ead.archdesc[:dsc]
|
67
|
+
c01 = dsc[:c]
|
68
|
+
assert(c01, "Check that the level was imported")
|
69
|
+
assert(c01[:did], "Check that the description was imported")
|
70
|
+
|
71
|
+
c02 = c01[:c]
|
72
|
+
assert(c02, "Check that the second level was imported")
|
73
|
+
assert(c02[:c], "Check that the third level was imported")
|
74
|
+
end
|
75
|
+
end
|
data/test/note_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestEADNote < Test::Unit::TestCase
|
4
|
+
def initialize(*args)
|
5
|
+
super(*args)
|
6
|
+
|
7
|
+
@test_file = "test_ead_note.xml"
|
8
|
+
@p = "Test p"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_attrs
|
12
|
+
dsc = EADCodec::Subordinates.new
|
13
|
+
@ead.archdesc << dsc
|
14
|
+
|
15
|
+
c01 = EADCodec::Level.new
|
16
|
+
dsc << c01
|
17
|
+
|
18
|
+
note = EADCodec::Note.new
|
19
|
+
note << EADCodec::P.new(@p)
|
20
|
+
note << EADCodec::P.new(@p)
|
21
|
+
c01 << note
|
22
|
+
|
23
|
+
export
|
24
|
+
element_exists("/ead/archdesc/dsc/c/note", "Check that the note was added")
|
25
|
+
compare_xpath(@p, "/ead/archdesc/dsc/c/note/p")
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def test_import
|
30
|
+
import
|
31
|
+
note = @ead.archdesc[:dsc][:c][:note]
|
32
|
+
ps = note.find_all_named(:p)
|
33
|
+
assert_equal(@p, ps[0].value)
|
34
|
+
assert_equal(@p, ps[1].value)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestPartialExport < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@test_file = "test_ead_partial_export.xml"
|
7
|
+
@head = "Test head"
|
8
|
+
@type = "combined"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_partial_export
|
12
|
+
file = File.open(filepath, "w")
|
13
|
+
|
14
|
+
did = EADCodec::Description.new
|
15
|
+
did << EADCodec::Head.new("abc")
|
16
|
+
did << EADCodec::UnitId.new("teste")
|
17
|
+
@ead.archdesc << did
|
18
|
+
|
19
|
+
dsc = EADCodec::Subordinates.new
|
20
|
+
dsc.type = @type
|
21
|
+
@ead.archdesc << dsc
|
22
|
+
|
23
|
+
c01 = EADCodec::Level.new
|
24
|
+
did = EADCodec::Description.new
|
25
|
+
did << EADCodec::Head.new("abc")
|
26
|
+
did << EADCodec::UnitId.new("teste")
|
27
|
+
did << EADCodec::UnitTitle.new("teste")
|
28
|
+
c01 << did
|
29
|
+
|
30
|
+
dsc << c01
|
31
|
+
c01.start_partial_export(file)
|
32
|
+
|
33
|
+
dsc = EADCodec::Subordinates.new
|
34
|
+
dsc.type = @type
|
35
|
+
c01 << dsc
|
36
|
+
|
37
|
+
c02 = EADCodec::Level.new
|
38
|
+
did = EADCodec::Description.new
|
39
|
+
did << EADCodec::Head.new("abc")
|
40
|
+
did << EADCodec::UnitId.new("teste")
|
41
|
+
did << EADCodec::UnitTitle.new("teste")
|
42
|
+
c02 << did
|
43
|
+
sc = EADCodec::ScopeContent.new
|
44
|
+
sc << EADCodec::P.new('value1')
|
45
|
+
sc << EADCodec::P.new('value2')
|
46
|
+
c02 << sc
|
47
|
+
|
48
|
+
dsc << c02
|
49
|
+
c02.start_partial_export(file)
|
50
|
+
|
51
|
+
@ead.end_partial_export(file)
|
52
|
+
|
53
|
+
file.close
|
54
|
+
|
55
|
+
validate_dtd
|
56
|
+
compare_xpath("fonds", "/ead/archdesc/@level")
|
57
|
+
compare_xpath(@type, "/ead/archdesc/dsc/@type")
|
58
|
+
element_exists("/ead/archdesc/dsc/c", "the first level was not added")
|
59
|
+
element_exists("/ead/archdesc/dsc/c/did", "the first level description was not added")
|
60
|
+
element_exists("/ead/archdesc/dsc/c/dsc/c", "the second level was not added")
|
61
|
+
element_exists("/ead/archdesc/dsc/c/dsc/c/did", "the second level description was not added")
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestEADPhysTech < Test::Unit::TestCase
|
4
|
+
def initialize(*args)
|
5
|
+
super(*args)
|
6
|
+
@test_file = "test_ead_phystech.xml"
|
7
|
+
@head = "HEADTest"
|
8
|
+
@ptext = "Some Text "
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_export
|
12
|
+
phystech = EADCodec::PhysTech.new
|
13
|
+
phystech << EADCodec::Head.new(@head)
|
14
|
+
(1..4).each {|i| phystech << EADCodec::P.new(@ptext+i.to_s)}
|
15
|
+
|
16
|
+
did = EADCodec::Description.new
|
17
|
+
did << EADCodec::Head.new("head")
|
18
|
+
did << EADCodec::UnitId.new("id")
|
19
|
+
|
20
|
+
@ead.archdesc << did
|
21
|
+
@ead.archdesc << phystech
|
22
|
+
export
|
23
|
+
|
24
|
+
# Since we've added content it is now valid EAD
|
25
|
+
validate_dtd
|
26
|
+
|
27
|
+
element_exists("/ead/archdesc/phystech", "Test did exists")
|
28
|
+
compare_xpath(@head, "/ead/archdesc/phystech/head")
|
29
|
+
(1..4).each do |i|
|
30
|
+
compare_xpath(@ptext+i.to_s, "/ead/archdesc/phystech/p["+i.to_s+"]")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def test_import
|
36
|
+
import
|
37
|
+
phystech = @ead.archdesc[:phystech]
|
38
|
+
|
39
|
+
assert_equal(@head, phystech[:head].value)
|
40
|
+
ps = phystech.find_all_named(:p)
|
41
|
+
(1..4).each do |i|
|
42
|
+
assert_equal(@ptext+i.to_s, ps[i-1].value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|