stead 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <ead xsi:schemaLocation="urn:isbn:1-931666-22-9 http://www.loc.gov/ead/ead.xsd"
3
+ xmlns:ns2="http://www.w3.org/1999/xlink"
4
+ xmlns="urn:isbn:1-931666-22-9"
5
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6
+ <eadheader findaidstatus="Completed" repositoryencoding="iso15511"
7
+ countryencoding="iso3166-1" dateencoding="iso8601">
8
+ <eadid></eadid>
9
+ <filedesc>
10
+ <titlestmt>
11
+ <titleproper>
12
+ Preliminary Inventory to the
13
+ </titleproper>
14
+ <author></author>
15
+ </titlestmt>
16
+ <publicationstmt>
17
+ <publisher>Special Collections Research Center</publisher>
18
+ </publicationstmt>
19
+ </filedesc>
20
+ <profiledesc>
21
+ <langusage>
22
+ Finding aid written in
23
+ <language langcode="eng" encodinganalog="Language">English.</language>
24
+ </langusage>
25
+ </profiledesc>
26
+ </eadheader>
27
+ <archdesc level="subgrp">
28
+ <did>
29
+ <unittitle>Preliminary Inventory to the</unittitle>
30
+ <unitid></unitid>
31
+ <langmaterial>
32
+ <language langcode="eng"/>
33
+ </langmaterial>
34
+ <physloc label="Location">
35
+ For current information on the location of these materials, please consult the
36
+ <extref ns2:type="simple" ns2:href="http://www.lib.ncsu.edu/specialcollections/research/requestinformation.html">
37
+ Special Collections Research Center Reference Staff
38
+ </extref>
39
+ .
40
+ </physloc>
41
+
42
+ </did>
43
+ <accessrestrict >
44
+ <head>Access to Collection</head>
45
+ <p>
46
+ Collection is open for research; access requires at least 24 hours advance notice.
47
+ </p>
48
+ </accessrestrict>
49
+ <userestrict>
50
+ <head>Copyright Notice</head>
51
+ <p>
52
+ The nature of the NCSU Libraries' Special Collections means that copyright or other information about restrictions may be difficult or even impossible to determine despite reasonable efforts. The NCSU Libraries claims only physical ownership of most Special Collections materials.
53
+ </p>
54
+ <p>
55
+ The materials from our collections are made available for use in research, teaching, and private study, pursuant to U.S. Copyright law. The user must assume full responsibility for any use of the materials, including but not limited to, infringement of copyright and publication rights of reproduced materials. Any materials used for academic research or otherwise should be fully credited with the source.
56
+ </p>
57
+ </userestrict>
58
+ <prefercite id="ref8">
59
+ <head>Preferred Citation</head>
60
+ <p>
61
+ [Identification of item], Collection title, Collection number, NCSU Libraries' Special Collections Research Center.
62
+ </p>
63
+ </prefercite>
64
+ <dsc>
65
+
66
+ </dsc>
67
+ </archdesc>
68
+ </ead>
69
+
data/lib/stead.rb ADDED
@@ -0,0 +1,56 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Stead
5
+ VERSION = '0.0.1'
6
+
7
+ CONTAINER_TYPES = [
8
+ "album",
9
+ "artifactbox",
10
+ "audiocassette",
11
+ "audiotape",
12
+ "box",
13
+ "cardbox",
14
+ "carton",
15
+ "cassette",
16
+ "cassettebox",
17
+ "cdbox",
18
+ "diskette",
19
+ "drawingsbox",
20
+ "flatbox",
21
+ "flatfile",
22
+ "flatfolder",
23
+ "folder",
24
+ "halfbox",
25
+ "item",
26
+ "largeenvelope",
27
+ "legalbox",
28
+ "mapcase",
29
+ "mapfolder",
30
+ "notecardbox",
31
+ "othertype",
32
+ "oversize",
33
+ "oversizebox",
34
+ "oversizeflatbox",
35
+ "reel",
36
+ "reelbox",
37
+ "scrapbook",
38
+ "slidebox",
39
+ "tube",
40
+ "tubebox",
41
+ "videotape",
42
+ "volume"
43
+ ]
44
+ end
45
+
46
+ require 'rubygems'
47
+ require 'nokogiri'
48
+ require 'fastercsv'
49
+ require 'active_support'
50
+
51
+ require 'pp'
52
+
53
+ require 'stead/stead'
54
+ require 'stead/ead'
55
+ require 'stead/error'
56
+
data/test/helper.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'stead'
8
+
9
+ class Test::Unit::TestCase
10
+ end
11
+
12
+ module SteadTestHelpers
13
+ def assert_main_elements_equal(did, example_did)
14
+ ['unitid', 'unittitle', 'unitdate', 'extent', 'container'].each do |elem|
15
+ #puts example_did.xpath('.//xmlns:' + elem)
16
+ if !example_did.xpath('.//xmlns:' + elem).blank?
17
+ did_content = did.xpath('.//xmlns:' + elem).first.content
18
+ assert_not_nil did_content
19
+ assert_equal example_did.xpath('.//xmlns:' + elem).first.content,
20
+ did_content
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ class TestSteadErrors < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @ead_generator = Stead::EadGenerator.from_csv(File.read(File.join(File.dirname(__FILE__),
7
+ 'container_lists', 'mc00000_container_list_bad_container_type.csv' )))
8
+ @ead_generator_good = Stead::EadGenerator.from_csv(File.read(File.join(File.dirname(__FILE__),
9
+ 'container_lists', 'mc00000_container_list_no_series.csv' )))
10
+ end
11
+
12
+ def test_bad_container_type_raises
13
+ assert_raise(Stead::InvalidContainerType) {@ead_generator.to_ead}
14
+ end
15
+
16
+ def test_bad_container_type_error_message
17
+ begin
18
+ @ead_generator.to_ead
19
+ rescue Stead::InvalidContainerType => error
20
+ assert_equal 'Box', error.message
21
+ end
22
+ end
23
+
24
+ # create an invalid ead document so that we can test that validation of the ead
25
+ # is working
26
+ def test_invalid_ead_error_message
27
+ assert_raise(Stead::InvalidEad) {
28
+ @ead_generator_good.to_ead
29
+ a = Nokogiri::XML::Node.new('asdfasd', @ead_generator_good.ead)
30
+ @ead_generator_good.ead.xpath('//xmlns:archdesc').first.add_child(a)
31
+ @ead_generator_good.valid?
32
+ }
33
+ end
34
+
35
+ def test_csv_with_nil_header
36
+ assert_raise(Stead::InvalidCsv) {
37
+ Stead::EadGenerator.from_csv(File.read(File.join(File.dirname(__FILE__),
38
+ 'container_lists', 'mc00084_container_list_empty_header.csv' ))) }
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,89 @@
1
+ require 'helper'
2
+
3
+ class TestSteadEadNoSeries < Test::Unit::TestCase
4
+ include SteadTestHelpers
5
+
6
+ def setup
7
+ @xsd = Nokogiri::XML::Schema(File.read(Stead.ead_schema))
8
+ #@template = Nokogiri::XML(File.read(Stead.ead_template))
9
+ @example = Nokogiri::XML(File.read(File.join(File.dirname(__FILE__),
10
+ 'container_lists', 'mc00000-ead.xml' )))
11
+ @ead_generator = Stead::EadGenerator.from_csv(File.read(File.join(File.dirname(__FILE__),
12
+ 'container_lists', 'mc00000_container_list_no_series.csv' )))
13
+ @generated_ead = @ead_generator.to_ead
14
+ #puts Stead.pretty_write(@generated_ead)
15
+ @did_xpath = '//xmlns:dsc/xmlns:c01/xmlns:did'
16
+ end
17
+
18
+ def test_creation_of_eadxml_counts
19
+ assert_equal 1, @example.xpath('//xmlns:dsc').length
20
+ assert_equal 1, @generated_ead.xpath('//xmlns:dsc').length
21
+ assert_equal 5, @generated_ead.xpath('//xmlns:c01').length
22
+ end
23
+
24
+ def test_created_ead_matches_example_content
25
+ (0..4).each do |number|
26
+ #puts number
27
+ did = @generated_ead.xpath(@did_xpath)[number]
28
+ example_did = @example.xpath(@did_xpath)[number]
29
+ assert_equal 'file', did.parent['level']
30
+ assert_main_elements_equal(did, example_did)
31
+ end
32
+ end
33
+
34
+ def test_notes
35
+ notes = @generated_ead.xpath(@did_xpath).first.xpath('xmlns:note')
36
+ assert_equal 'note1', notes.first.xpath('xmlns:p').first.content
37
+ assert_equal 'note2', notes[1].xpath('xmlns:p').first.content
38
+ end
39
+
40
+ def test_scopecontent
41
+ last_cp = @generated_ead.xpath('//xmlns:c01').last
42
+ scopecontent = last_cp.xpath('./xmlns:scopecontent/xmlns:p').first.content
43
+ assert_equal 'Sessions 32-38', scopecontent
44
+ end
45
+
46
+ def test_validity
47
+ assert @xsd.valid?(@generated_ead)
48
+ end
49
+
50
+ def test_internal_only
51
+ assert_equal 'internal',
52
+ @generated_ead.xpath(@did_xpath).first.parent['audience']
53
+ end
54
+
55
+ def test_accessrestrict
56
+ last_cp = @generated_ead.xpath('//xmlns:c01')[3]
57
+ accessrestrict = last_cp.xpath('./xmlns:accessrestrict').first.content
58
+ assert_equal 'Restricted', accessrestrict
59
+ end
60
+
61
+ def test_container_label
62
+ container = @generated_ead.xpath('//xmlns:container').first
63
+ assert_equal 'Mixed materials', container['label']
64
+ end
65
+
66
+ def test_three_containers
67
+ first_did = @generated_ead.xpath(@did_xpath).first
68
+ containers = first_did.xpath('xmlns:container')
69
+ assert_equal 3, containers.length
70
+ assert_equal 'box', containers.first['type']
71
+ assert_equal '45', containers.first.content
72
+ assert_equal 'folder', containers[1]['type']
73
+ assert_equal '404', containers[1].content
74
+ assert_equal 'artifactbox', containers[2]['type']
75
+ assert_equal '3', containers[2].content
76
+ end
77
+
78
+ def test_missing_container_type
79
+ did = @generated_ead.xpath(@did_xpath)[3]
80
+ containers = did.xpath('xmlns:container')
81
+ assert_equal 2, containers.length
82
+ assert_equal 'box', containers[0]['type']
83
+ assert_equal '58', containers[0].content
84
+ assert_equal 'othertype', containers[1]['type']
85
+ assert_equal '551', containers[1].content
86
+ end
87
+
88
+ end
89
+
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ class TestSteadEadSeries < Test::Unit::TestCase
4
+ include SteadTestHelpers
5
+
6
+ def setup
7
+ @xsd = Nokogiri::XML::Schema(File.read(Stead.ead_schema))
8
+ #@template = Nokogiri::XML(File.read(Stead.ead_template))
9
+ @example = Nokogiri::XML(File.read(File.join(File.dirname(__FILE__),
10
+ 'container_lists', 'mc00000-ead-series.xml' )))
11
+ @ead_generator = Stead::EadGenerator.from_csv(File.read(File.join(File.dirname(__FILE__),
12
+ 'container_lists', 'mc00000_container_list.csv' )))
13
+ @generated_ead = @ead_generator.to_ead
14
+ #puts Stead.pretty_write(@generated_ead)
15
+ @did_xpath = '//xmlns:c02/xmlns:did'
16
+ end
17
+
18
+ def test_ead_c01_counts
19
+ assert_equal 3, @generated_ead.xpath('//xmlns:c01').length
20
+ end
21
+
22
+ def test_ead_c02_counts
23
+ assert_equal 5, @generated_ead.xpath('//xmlns:c02').length
24
+ end
25
+
26
+ def test_validity
27
+ assert @xsd.valid?(@generated_ead)
28
+ end
29
+
30
+ def test_created_ead_matches_example_content
31
+ (0..4).each do |number|
32
+ #puts number
33
+ did = @generated_ead.xpath(@did_xpath)[number]
34
+ example_did = @example.xpath(@did_xpath)[number]
35
+ assert_equal 'file', did.parent['level']
36
+ assert_main_elements_equal(did, example_did)
37
+ end
38
+ end
39
+
40
+
41
+ end
42
+
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+
3
+ class TestStead < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @xsd = Stead.xsd
7
+ @template = Nokogiri::XML(File.read(Stead.ead_template))
8
+ @example = Nokogiri::XML(File.read(File.join(File.dirname(__FILE__),
9
+ 'container_lists', 'mc00000-ead.xml' )))
10
+ @output = Stead::EadGenerator.from_csv(File.read(File.join(File.dirname(__FILE__),
11
+ 'container_lists', 'mc00000_container_list_no_series.csv' )))
12
+ end
13
+
14
+ def test_truth
15
+ assert true
16
+ end
17
+
18
+ def test_validity_of_ead_template
19
+ assert @xsd.valid?(@template)
20
+ end
21
+
22
+ def test_validity_of_ead_example_document
23
+ assert @xsd.valid?(@example)
24
+ end
25
+
26
+ context "optional elements to add" do
27
+ setup do
28
+ file = File.read(File.join(File.dirname(__FILE__),
29
+ 'container_lists', 'mc00000_container_list_no_series.csv' ))
30
+ options = {:eadid => 'mc00000', :base_url => 'http://www.lib.ncsu.edu/findingaids'}
31
+ @generator = Stead::EadGenerator.from_csv(file, options)
32
+ @ead = @generator.to_ead
33
+ end
34
+ should "add the eadid if supplied" do
35
+ assert_equal 'mc00000', @ead.xpath('//xmlns:eadid').first.content
36
+ end
37
+ should "add an ead url if supplied" do
38
+ assert_equal 'http://www.lib.ncsu.edu/findingaids/mc00000', @ead.xpath('//xmlns:eadid').first['url']
39
+ end
40
+ end
41
+
42
+ end
43
+
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stead
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Jason Ronallo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-08 00:00:00 -04:00
19
+ default_executable: csv2ead
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 1
34
+ version: 1.4.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: fastercsv
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 1
48
+ - 5
49
+ - 0
50
+ version: 1.5.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: activesupport
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 9
62
+ segments:
63
+ - 2
64
+ - 3
65
+ - 5
66
+ version: 2.3.5
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: trollop
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 83
78
+ segments:
79
+ - 1
80
+ - 16
81
+ - 2
82
+ version: 1.16.2
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: shoulda
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ description: Converts CSV files of a specific schema into EAD XML.
100
+ email: jronallo@gmail.com
101
+ executables:
102
+ - csv2ead
103
+ extensions: []
104
+
105
+ extra_rdoc_files:
106
+ - LICENSE
107
+ - README.rdoc
108
+ files:
109
+ - LICENSE
110
+ - README.rdoc
111
+ - Rakefile
112
+ - VERSION
113
+ - bin/csv2ead
114
+ - examples/ncsu.rb
115
+ - lib/stead.rb
116
+ - lib/stead/ead.rb
117
+ - lib/stead/error.rb
118
+ - lib/stead/stead.rb
119
+ - lib/stead/templates/ead.xml
120
+ - lib/stead/templates/ead.xsd
121
+ - lib/stead/templates/ncsu_ead.xml
122
+ - test/test_ead_bad_container_type.rb
123
+ - test/helper.rb
124
+ - test/test_stead.rb
125
+ - test/test_ead_no_series.rb
126
+ - test/test_ead_series.rb
127
+ has_rdoc: true
128
+ homepage: http://github.com/jronallo/stead
129
+ licenses: []
130
+
131
+ post_install_message:
132
+ rdoc_options:
133
+ - --charset=UTF-8
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ requirements: []
155
+
156
+ rubyforge_project:
157
+ rubygems_version: 1.3.7
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Spreadsheets To Encoded Archival Description
161
+ test_files:
162
+ - test/test_ead_bad_container_type.rb
163
+ - test/helper.rb
164
+ - test/test_stead.rb
165
+ - test/test_ead_no_series.rb
166
+ - test/test_ead_series.rb
167
+ - examples/ncsu.rb