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
data/Rakefile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PKG_NAME = 'eadcodec'
|
2
|
-
PKG_VERSION = '0.0
|
2
|
+
PKG_VERSION = '0.1.0'
|
3
3
|
|
4
4
|
require 'rake'
|
5
5
|
require 'rake/testtask'
|
6
6
|
require 'rake/rdoctask'
|
7
7
|
require 'rake/gempackagetask'
|
8
8
|
require 'rubygems'
|
9
|
+
require 'rcov/rcovtask'
|
9
10
|
|
10
11
|
task :default => ['test']
|
11
12
|
|
@@ -30,7 +31,7 @@ spec = Gem::Specification.new do |s|
|
|
30
31
|
s.author = 'Pedro Côrte-Real'
|
31
32
|
s.email = 'pedrocr@gmail.com'
|
32
33
|
s.requirements << 'xmlcodec'
|
33
|
-
s.add_dependency('xmlcodec', '>= 0.0
|
34
|
+
s.add_dependency('xmlcodec', '>= 0.1.0')
|
34
35
|
s.require_path = 'lib'
|
35
36
|
s.autorequire = 'rake'
|
36
37
|
s.files = PKG_FILES
|
@@ -50,9 +51,8 @@ end
|
|
50
51
|
|
51
52
|
Rake::TestTask.new do |t|
|
52
53
|
t.libs << "test"
|
53
|
-
t.test_files = FileList['test
|
54
|
-
t.libs = ['
|
55
|
-
t.ruby_opts = ['-xtest']
|
54
|
+
t.test_files = FileList['test/*_test.rb']
|
55
|
+
t.libs = ['lib']
|
56
56
|
t.verbose = true
|
57
57
|
end
|
58
58
|
|
@@ -77,6 +77,13 @@ task :stats do
|
|
77
77
|
puts "Code to test ratio: 1:%.2f" % ratio
|
78
78
|
end
|
79
79
|
|
80
|
+
Rcov::RcovTask.new do |t|
|
81
|
+
t.libs << "test"
|
82
|
+
t.test_files = FileList['test/*_test.rb']
|
83
|
+
t.output_dir = 'test/coverage'
|
84
|
+
t.verbose = true
|
85
|
+
end
|
86
|
+
|
80
87
|
def count_lines(files)
|
81
88
|
code = 0
|
82
89
|
comments = 0
|
data/lib/eadcodec.rb
CHANGED
@@ -1 +1,76 @@
|
|
1
|
-
require
|
1
|
+
require "rexml/document"
|
2
|
+
require "xmlcodec"
|
3
|
+
|
4
|
+
# This module includes all the support for EAD import/export. The main class to
|
5
|
+
# use is EADDocument that is a subclass of XMLUtils::XMLElement. All elements
|
6
|
+
# supported are based on the EAD DTD and have the same names. Currently not all
|
7
|
+
# attributes and elements have been added. Adding an element is pretty easy
|
8
|
+
# though.
|
9
|
+
module EADCodec
|
10
|
+
class EADElement < XMLCodec::XMLElement #:nodoc:
|
11
|
+
xmlformat 'EAD'
|
12
|
+
end
|
13
|
+
|
14
|
+
class EADSimpleElement < EADElement
|
15
|
+
elwithvalue
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
include XMLUtils
|
23
|
+
|
24
|
+
def self.sclass(name, string)
|
25
|
+
const_set(name, Class.new(EADSimpleElement)).send(:elname, string)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create a bunch of classes for simple elements with just values
|
29
|
+
# Most of these actually can have children so they should be promoted to
|
30
|
+
# actual classes.
|
31
|
+
sclass "Abstract", "abstract"
|
32
|
+
sclass "Author", "author"
|
33
|
+
sclass "Sponsor", "sponsor"
|
34
|
+
sclass "TitleProper", "titleproper"
|
35
|
+
sclass "Abbr", "abbr"
|
36
|
+
sclass "Emph", "emph"
|
37
|
+
sclass "Expan", "expan"
|
38
|
+
sclass "ExtPtr", "extptr"
|
39
|
+
sclass "Lb", "lb"
|
40
|
+
sclass "Num", "num"
|
41
|
+
sclass "Ptr", "ptr"
|
42
|
+
sclass "ArchRef", "archref"
|
43
|
+
sclass "BibRef", "bibref"
|
44
|
+
sclass "ExtRef", "extref"
|
45
|
+
sclass "Ref", "ref"
|
46
|
+
sclass "LinkGrp", "linkgrp"
|
47
|
+
sclass "Title", "title"
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
# Module included in classes that have paragraphs as subelements
|
52
|
+
module WithParagraphs
|
53
|
+
def initialize(value=nil)
|
54
|
+
value = [] if not value
|
55
|
+
value = [value] if not value.is_a? Array
|
56
|
+
value.each{|v| self << P.new(v)}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Module included in classes that have text and other elements as subelements
|
61
|
+
module WithText
|
62
|
+
def initialize(value=nil)
|
63
|
+
value = [] if not value
|
64
|
+
value = [value] if not value.is_a? Array
|
65
|
+
value.each{|v| self << v}
|
66
|
+
end
|
67
|
+
|
68
|
+
def value
|
69
|
+
self.subelements[0].to_s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Dir.glob(File.dirname(__FILE__)+'/elements/*.rb').each do |el|
|
75
|
+
EADCodec.module_eval File.open(el).read
|
76
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ArchDesc < EADElement
|
2
|
+
elname "archdesc"
|
3
|
+
|
4
|
+
xmlattr :altrender
|
5
|
+
xmlattr :audience
|
6
|
+
xmlattr :encodinganalog
|
7
|
+
xmlattr :id
|
8
|
+
xmlattr :level
|
9
|
+
xmlattr :otherlevel
|
10
|
+
xmlattr :relatedencoding
|
11
|
+
xmlattr :type
|
12
|
+
|
13
|
+
xmlsubelements
|
14
|
+
def initialize
|
15
|
+
@level = "fonds"
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_content
|
19
|
+
text = create_open_tag+"\n"
|
20
|
+
each_subel do |name|
|
21
|
+
if not subel_mult?(name)
|
22
|
+
value = send(name)
|
23
|
+
if value
|
24
|
+
doc = REXML::Document.new
|
25
|
+
xml = value.create_xml(doc)
|
26
|
+
doc.write(text,2)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
text
|
31
|
+
end
|
32
|
+
end
|
data/lib/elements/c.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
class Level < EADElement
|
2
|
+
xmlattr :altrender
|
3
|
+
xmlattr :audience
|
4
|
+
xmlattr :encodinganalog
|
5
|
+
xmlattr :id
|
6
|
+
xmlattr :level
|
7
|
+
xmlattr :otherlevel
|
8
|
+
xmlattr :tpattern
|
9
|
+
|
10
|
+
xmlsubelements
|
11
|
+
|
12
|
+
attr_reader :parent
|
13
|
+
|
14
|
+
#elnames(*["c","c01","c02","c03","c04","c05","c06",
|
15
|
+
# "c07","c08","c09","c10","c11","c12"])
|
16
|
+
|
17
|
+
elname 'c'
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@unnumbered = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_unnumbered
|
24
|
+
@unnumbered = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_numbered
|
28
|
+
@unnumbered = false
|
29
|
+
end
|
30
|
+
|
31
|
+
def unnumbered?
|
32
|
+
if not instance_variables.index('@unnumbered')
|
33
|
+
@unnumbered = false
|
34
|
+
end
|
35
|
+
@unnumbered
|
36
|
+
end
|
37
|
+
|
38
|
+
def __parent=(parent)
|
39
|
+
super
|
40
|
+
if parent.unnumbered?
|
41
|
+
self.set_unnumbered
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def description_level
|
46
|
+
if __parent
|
47
|
+
return __parent.description_level + 1
|
48
|
+
else
|
49
|
+
return 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#alias_method :oldelname, :elname # Just to shut up the warning
|
54
|
+
#def elname
|
55
|
+
# if unnumbered?
|
56
|
+
# return "c"
|
57
|
+
# end
|
58
|
+
|
59
|
+
# if description_level < 10
|
60
|
+
# return "c0" + description_level.to_s
|
61
|
+
# else
|
62
|
+
# return "c" + description_level.to_s
|
63
|
+
# end
|
64
|
+
#end
|
65
|
+
end
|
data/lib/elements/dsc.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Subordinates < EADElement
|
2
|
+
elname "dsc"
|
3
|
+
|
4
|
+
xmlattr :altrender
|
5
|
+
xmlattr :audience
|
6
|
+
xmlattr :encondinganalog
|
7
|
+
xmlattr :id
|
8
|
+
xmlattr :othertype
|
9
|
+
xmlattr :tpattern
|
10
|
+
xmlattr :type
|
11
|
+
|
12
|
+
xmlsubelements
|
13
|
+
|
14
|
+
def description_level
|
15
|
+
0
|
16
|
+
end
|
17
|
+
|
18
|
+
def unnumbered?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
data/lib/elements/ead.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class Document < EADElement
|
2
|
+
elname "ead"
|
3
|
+
|
4
|
+
COUNTRY_CODE = "pt"
|
5
|
+
AGENCY_CODE = "iantt"
|
6
|
+
|
7
|
+
xmlsubel :eadheader
|
8
|
+
xmlsubel :archdesc
|
9
|
+
|
10
|
+
def self.from_file(file)
|
11
|
+
doc = REXML::Document.new(File.new(file))
|
12
|
+
self.import_xml(doc.elements[1])
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(id, title)
|
16
|
+
self.eadheader = Header.new(id, title)
|
17
|
+
self.archdesc = ArchDesc.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def export(filename)
|
21
|
+
doc = REXML::Document.new
|
22
|
+
doc << REXML::XMLDecl.new("1.0", "UTF-8")
|
23
|
+
doc << REXML::DocType.new("ead SYSTEM", '"file:///home/pedrocr/ead.dtd"')
|
24
|
+
create_xml(doc)
|
25
|
+
output = File.open(filename, "w")
|
26
|
+
|
27
|
+
doc.write(output, 0)
|
28
|
+
output.write "\n"
|
29
|
+
output.close
|
30
|
+
end
|
31
|
+
|
32
|
+
def start_partial_export(file)
|
33
|
+
if not already_partial_exported?
|
34
|
+
file << "<?xml version='1.0' encoding='UTF-8'?>\n"
|
35
|
+
file << "<!DOCTYPE ead SYSTEM \"file:///home/pedrocr/ead.dtd\">\n"
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Header < EADElement
|
2
|
+
elname 'eadheader'
|
3
|
+
|
4
|
+
xmlattr :altrender
|
5
|
+
xmlattr :audience
|
6
|
+
xmlattr :countryenconding
|
7
|
+
xmlattr :dateencoding
|
8
|
+
xmlattr :encodinganalog
|
9
|
+
xmlattr :findaidstatus
|
10
|
+
xmlattr :id
|
11
|
+
xmlattr :langenconding
|
12
|
+
xmlattr :relatedencoding
|
13
|
+
xmlattr :repositoryencoding
|
14
|
+
xmlattr :scriptencoding
|
15
|
+
|
16
|
+
xmlsubel :eadid
|
17
|
+
xmlsubel :filedesc
|
18
|
+
xmlsubel :profiledesc
|
19
|
+
|
20
|
+
def initialize(id, title)
|
21
|
+
self.eadid = Id.new(id)
|
22
|
+
self.filedesc = FileDesc.new(title)
|
23
|
+
end
|
24
|
+
|
25
|
+
def eadtitle
|
26
|
+
self.filedesc.titlestmt.titleproper
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class GeogName < EADElement
|
2
|
+
include WithText
|
3
|
+
elname 'geogname'
|
4
|
+
|
5
|
+
xmlattr :altrender
|
6
|
+
xmlattr :audience
|
7
|
+
xmlattr :authfilenumber
|
8
|
+
xmlattr :encondinganalog
|
9
|
+
xmlattr :id
|
10
|
+
xmlattr :normal
|
11
|
+
xmlattr :role
|
12
|
+
xmlattr :rules
|
13
|
+
xmlattr :source
|
14
|
+
|
15
|
+
xmlsubelements
|
16
|
+
end
|
data/lib/elements/id.rb
ADDED