mead 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ module Mead
2
+ module Validations
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ def validate
8
+ errors.clear
9
+ self.class.validations.each do |validation|
10
+ validation.call(self)
11
+ end
12
+ end
13
+
14
+ def validate_format
15
+ errors.clear
16
+ self.class.format_validations.each do |validation|
17
+ validation.call(self)
18
+ end
19
+ end
20
+
21
+ def valid?
22
+ validate_format
23
+ validate
24
+ errors.nil? or errors.empty?
25
+ end
26
+
27
+ def valid_format?
28
+ validate_format
29
+ errors.nil? or errors.empty?
30
+ end
31
+
32
+ def errors
33
+ @errors ||= {}
34
+ end
35
+
36
+ module ClassMethods
37
+ def validations
38
+ @validations ||= []
39
+ end
40
+
41
+ def format_validations
42
+ @format_validations ||= []
43
+ end
44
+
45
+ def add_error(instance, attribute, message)
46
+ if instance.errors[attribute]
47
+ instance.errors[attribute] << message
48
+ else
49
+ instance.errors[attribute] = [message]
50
+ end
51
+ end
52
+
53
+ # FIXME: This should be a more generic regular expression. Overriding this
54
+ # method is the way to use a different regular expression during format
55
+ # validation.
56
+ def format_regexp
57
+ container_codes = Mead::CONTAINER_MAPPING.keys.join('|')
58
+ #/^(ua\d{3}|mc\d{5})(_\d{3})?-\d{3}-(#{container_codes})\d{4}-\d{3}([A-Z])?-\d{3}(_\d{4})?$/ # NCSU specific
59
+ # eadid series box/container folder sequence page
60
+ /^([a-z0-9_]*)-\d{3}-(#{container_codes})\d{4}-\d{3}([A-Z])?-\d{3}(_\d{4})?$/
61
+ end
62
+
63
+ def validates_format_of_mead
64
+ validates_format do |instance|
65
+ add_error(instance, :mead, "Can't be blank.") if instance.mead.nil? or instance.mead.empty?
66
+ # check the format of the whole thing
67
+ # ua023_031-001-cb0003-005-001
68
+ unless instance.mead.to_s =~ format_regexp
69
+ add_error(instance, :mead, 'Does not match regular expression.')
70
+ end
71
+ end
72
+ end
73
+
74
+ def validates_presence_of_mead
75
+ validates do |instance|
76
+ begin
77
+ if instance.metadata
78
+ result = instance.metadata
79
+ else
80
+ result = Mead::Extractor.new(instance).extract
81
+ end
82
+ if result.nil? or result.empty?
83
+ add_error(instance, :mead, 'No matching container.')
84
+ # even if the instance.series is 1 there may not be any series in the EAD XML yet
85
+ elsif result.last[:series_number] and instance.series != result.last[:series_number].to_s
86
+ add_error(instance, :mead, 'Bad series.')
87
+ end
88
+ rescue => e
89
+ add_error(instance, :mead, e)
90
+ end
91
+ end
92
+ end
93
+
94
+ def validates_numericality_of_mead(*attributes)
95
+ validates_attributes(*attributes) do |instance, attribute, value, options|
96
+ if value
97
+ unless value.to_s =~ /\A[+-]?\d+\Z/
98
+ add_error(instance, attribute, "Not a number.")
99
+ next
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def validates_attributes(*attributes, &proc)
106
+ validations << Proc.new { |instance|
107
+ attributes.each {|attribute|
108
+ proc.call(instance, attribute, instance.__send__(attribute))
109
+ }
110
+ }
111
+ end
112
+
113
+ def validates(&proc)
114
+ validations << Proc.new{|instance|
115
+ proc.call(instance)
116
+ }
117
+ end
118
+
119
+ def validates_format(&proc)
120
+ format_validations << Proc.new{|instance|
121
+ proc.call(instance)
122
+ }
123
+ end
124
+
125
+
126
+ end
127
+
128
+ end
129
+ end
130
+
data/lib/mead.rb ADDED
@@ -0,0 +1,71 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'open-uri'
5
+
6
+ require 'rubygems'
7
+ require 'nokogiri'
8
+ require 'csv'
9
+ if CSV.const_defined? :Reader
10
+ require 'fastercsv'
11
+ end
12
+ require 'json'
13
+
14
+ module Mead
15
+ CONTAINER_MAPPING = {
16
+ 'am' => 'album',
17
+ 'ab' => 'artifactbox',
18
+ 'ac' => 'audiocassette',
19
+ 'at' => 'audiotape',
20
+ 'bx' => 'box',
21
+ 'cb' => 'cardbox',
22
+ 'cn' => 'carton',
23
+ 'ce' => 'cassette',
24
+ 'cx' => 'cassettebox',
25
+ 'cd' => 'cdbox',
26
+ 'de' => 'diskette',
27
+ 'db' => 'drawingsbox',
28
+ 'fb' => 'flatbox',
29
+ 'fe' => 'flatfile',
30
+ 'ff' => 'flatfolder',
31
+ 'fr' => 'folder',
32
+ 'hb' => 'halfbox',
33
+ 'im' => 'item',
34
+ 'le' => 'largeenvelope',
35
+ 'lb' => 'legalbox',
36
+ 'mc' => 'mapcase',
37
+ 'mf' => 'mapfolder',
38
+ 'nb' => 'notecardbox',
39
+ 'ot' => 'othertype',
40
+ 'oe' => 'oversize',
41
+ 'ox' => 'oversizebox',
42
+ 'of' => 'oversizeflatbox',
43
+ 'rl' => 'reel',
44
+ 'rb' => 'reelbox',
45
+ 'sk' => 'scrapbook',
46
+ 'sb' => 'slidebox',
47
+ 'te' => 'tube',
48
+ 'vt' => 'videotape',
49
+ 've' => 'volume'
50
+ }
51
+ end
52
+
53
+ require 'mead/validations'
54
+ require 'mead/identifier'
55
+ require 'mead/extractor'
56
+ require 'mead/ead'
57
+ require 'mead/ead_validator'
58
+ require 'mead/container'
59
+
60
+ # if gbarcode and rmagick can both be loaded then load mead/barcode
61
+ begin
62
+ require 'gbarcode'
63
+ begin
64
+ require 'RMagick'
65
+ require 'tempfile'
66
+ require 'mead/barcode'
67
+ rescue LoadError
68
+ end
69
+ rescue LoadError
70
+ end
71
+
data/mead.gemspec ADDED
@@ -0,0 +1,142 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mead}
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Ronallo"]
12
+ s.date = %q{2011-02-03}
13
+ s.description = %q{Extract identifiers and metadata from EAD XML.}
14
+ s.email = %q{jronallo@gmail.com}
15
+ s.executables = ["mead2barcode", "meadbfv", "emv", "automead", "ead2meads"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/automead",
29
+ "bin/ead2meads",
30
+ "bin/emv",
31
+ "bin/mead2barcode",
32
+ "bin/meadbfv",
33
+ "lib/mead.rb",
34
+ "lib/mead/barcode.rb",
35
+ "lib/mead/container.rb",
36
+ "lib/mead/ead.rb",
37
+ "lib/mead/ead_validator.rb",
38
+ "lib/mead/extractor.rb",
39
+ "lib/mead/identifier.rb",
40
+ "lib/mead/trollop.rb",
41
+ "lib/mead/validations.rb",
42
+ "mead.gemspec",
43
+ "test/ead/mc00145.xml",
44
+ "test/ead/mc00240.xml",
45
+ "test/ead/ua015_010.xml",
46
+ "test/ead/ua021_428.xml",
47
+ "test/ead/ua023_006.xml",
48
+ "test/ead/ua023_031.xml",
49
+ "test/ead/ua110_041.xml",
50
+ "test/fixtures/mc00310.xml",
51
+ "test/fixtures/ua023_031.xml",
52
+ "test/helper.rb",
53
+ "test/test_barcode.rb",
54
+ "test/test_ead.rb",
55
+ "test/test_ead_validator.rb",
56
+ "test/test_extractor.rb",
57
+ "test/test_mc00145.rb",
58
+ "test/test_mc00240.rb",
59
+ "test/test_mead.rb",
60
+ "test/test_ua015_010.rb",
61
+ "test/test_ua021_428.rb",
62
+ "test/test_ua023_006_buildings.rb",
63
+ "test/test_ua023_006_faculty.rb",
64
+ "test/test_ua110_041.rb",
65
+ "test/test_validations.rb",
66
+ "watchr.rb"
67
+ ]
68
+ s.homepage = %q{http://github.com/jronallo/mead}
69
+ s.licenses = ["MIT"]
70
+ s.require_paths = ["lib"]
71
+ s.rubygems_version = %q{1.3.7}
72
+ s.summary = %q{Extract identifiers and metadata from EAD XML.}
73
+ s.test_files = [
74
+ "test/helper.rb",
75
+ "test/test_barcode.rb",
76
+ "test/test_ead.rb",
77
+ "test/test_ead_validator.rb",
78
+ "test/test_extractor.rb",
79
+ "test/test_mc00145.rb",
80
+ "test/test_mc00240.rb",
81
+ "test/test_mead.rb",
82
+ "test/test_ua015_010.rb",
83
+ "test/test_ua021_428.rb",
84
+ "test/test_ua023_006_buildings.rb",
85
+ "test/test_ua023_006_faculty.rb",
86
+ "test/test_ua110_041.rb",
87
+ "test/test_validations.rb"
88
+ ]
89
+
90
+ if s.respond_to? :specification_version then
91
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
92
+ s.specification_version = 3
93
+
94
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
95
+ s.add_runtime_dependency(%q<rmagick>, [">= 0"])
96
+ s.add_runtime_dependency(%q<nokogiri>, ["= 1.4.3.1"])
97
+ s.add_runtime_dependency(%q<json>, [">= 0"])
98
+ s.add_runtime_dependency(%q<trollop>, [">= 0"])
99
+ s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
100
+ s.add_runtime_dependency(%q<gbarcode>, [">= 0.98.20"])
101
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
102
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
103
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
104
+ s.add_development_dependency(%q<rcov>, [">= 0"])
105
+ s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
106
+ s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
107
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
108
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
109
+ else
110
+ s.add_dependency(%q<rmagick>, [">= 0"])
111
+ s.add_dependency(%q<nokogiri>, ["= 1.4.3.1"])
112
+ s.add_dependency(%q<json>, [">= 0"])
113
+ s.add_dependency(%q<trollop>, [">= 0"])
114
+ s.add_dependency(%q<fastercsv>, [">= 0"])
115
+ s.add_dependency(%q<gbarcode>, [">= 0.98.20"])
116
+ s.add_dependency(%q<shoulda>, [">= 0"])
117
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
118
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
119
+ s.add_dependency(%q<rcov>, [">= 0"])
120
+ s.add_dependency(%q<reek>, ["~> 1.2.8"])
121
+ s.add_dependency(%q<roodi>, ["~> 2.1.0"])
122
+ s.add_dependency(%q<fakeweb>, [">= 0"])
123
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
124
+ end
125
+ else
126
+ s.add_dependency(%q<rmagick>, [">= 0"])
127
+ s.add_dependency(%q<nokogiri>, ["= 1.4.3.1"])
128
+ s.add_dependency(%q<json>, [">= 0"])
129
+ s.add_dependency(%q<trollop>, [">= 0"])
130
+ s.add_dependency(%q<fastercsv>, [">= 0"])
131
+ s.add_dependency(%q<gbarcode>, [">= 0.98.20"])
132
+ s.add_dependency(%q<shoulda>, [">= 0"])
133
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
134
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
135
+ s.add_dependency(%q<rcov>, [">= 0"])
136
+ s.add_dependency(%q<reek>, ["~> 1.2.8"])
137
+ s.add_dependency(%q<roodi>, ["~> 2.1.0"])
138
+ s.add_dependency(%q<fakeweb>, [">= 0"])
139
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
140
+ end
141
+ end
142
+
@@ -0,0 +1,157 @@
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" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns="urn:isbn:1-931666-22-9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <eadheader findaidstatus="Completed" repositoryencoding="iso15511" countryencoding="iso3166-1" dateencoding="iso8601" langencoding="iso639-2b">
4
+ <eadid url="http://www.lib.ncsu.edu/findingaids/mc00145/">mc00145</eadid>
5
+ <filedesc>
6
+ <titlestmt>
7
+ <titleproper>Preliminary Inventory to the Gil Wheless Papers
8
+ <num>MC 00145</num>
9
+ </titleproper>
10
+ <author>Finding aid prepared by Todd Kosmerick</author>
11
+ </titlestmt>
12
+ <publicationstmt>
13
+ <publisher>Special Collections Research Center</publisher>
14
+ <date>2009-2010</date>
15
+ </publicationstmt>
16
+ </filedesc>
17
+ <profiledesc>
18
+ <creation>This finding aid was produced using the Archivists' Toolkit
19
+ <date>2011-01-21T15:31-0500</date>
20
+ </creation>
21
+ <langusage>English</langusage>
22
+ <descrules>Describing Archives: A Content Standard</descrules>
23
+ </profiledesc>
24
+ </eadheader>
25
+ <archdesc level="collection">
26
+ <did>
27
+ <unittitle>Gil Wheless Drawings</unittitle>
28
+ <unitid>MC 00145</unitid>
29
+ <repository>
30
+ <corpname>Special Collections Research Center</corpname>
31
+ </repository>
32
+ <langmaterial>
33
+ <language langcode="eng"/>
34
+ </langmaterial>
35
+ <physdesc>
36
+ <extent>69.0 Linear feet</extent>
37
+ <extent>3 cartons, 60 tubes, 7 flat folders</extent>
38
+ </physdesc>
39
+ <unitdate normal="1965/2005" type="inclusive">circa 1965 - circa 2005</unitdate>
40
+ <abstract id="ref13" label="Abstract">This collection contains materials from the career of landscape architect Gil Wheless: drawings of plans, photographs, CDs of CAD drawings, sketches, prinouts of CAD drawings, newsclippins, brochures, pamphlets, and other records.</abstract>
41
+ <abstract id="ref14" label="Abstract">Gil Wheless grew up in Durham, North Carolina. During the 1960s he attended North Carolina State University's School of Design, eventually entering the landscape architecture program. He studied under Richard Moore and Lewis Clarke. He worked with A.E. Bye in Connecticut and later became a principal partner in Environmental Design Associates.</abstract>
42
+ <origination label="creator">
43
+ <persname rules="aacr" source="local">Wheless, Gil</persname>
44
+ </origination>
45
+ </did>
46
+ <scopecontent id="ref1">
47
+ <head>Scope and Content Note</head>
48
+ <p>This collection contains materials from the career of landscape architect Gil Wheless: drawings of plans, photographs, CDs of CAD drawings, sketches, prinouts of CAD drawings, newsclippings, brochures, pamphlets, and other records.</p>
49
+ </scopecontent>
50
+ <bioghist id="ref7">
51
+ <head>Biographical Note</head>
52
+ <p>Gil Wheless grew up in Durham, North Carolina. During the 1960s he attended North Carolina State University's School of Design, eventually entering the landscape architecture program. He studied under Richard Moore and Lewis Clarke.</p>
53
+ <p>Wheless first worked with A.E. Bye in Connecticut. Later he became a principal partner in Environmental Design Associates, a landscape architecture firm established in 1968 and reorganized as a professional corporation in 1970. The firm is located in Wilton, Connecticut.</p>
54
+ <p></p>
55
+ </bioghist>
56
+ <arrangement id="ref8">
57
+ <head>Organization of the Collection</head>
58
+ <p>The materials are arranged in the order received. This collection has not yet received full archival processing.</p>
59
+ </arrangement>
60
+ <accessrestrict id="ref9">
61
+ <head>Restrictions to Access</head>
62
+ <p>Collection is open for research; access requires at least 24 hours advance notice.</p>
63
+ </accessrestrict>
64
+ <userestrict id="ref10">
65
+ <head>Copyright Notice</head>
66
+ <p>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.</p>
67
+ <p>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.</p>
68
+ </userestrict>
69
+ <prefercite id="ref12">
70
+ <head>Preferred Citation</head>
71
+ <p>[Identification of item], Gil Wheless Papers, MC 00145, Special Collections Research Center, North Carolina State University Libraries, Raleigh, NC</p>
72
+ </prefercite>
73
+ <acqinfo id="ref11">
74
+ <head>Acquisition Information</head>
75
+ <p>Gift of Gil Wheless, 2009 (Accession 2009-0132) and 2010 (Accession 2010-0007).</p>
76
+ </acqinfo>
77
+ <controlaccess>
78
+ <persname rules="aacr" source="local">Wheless, Gil</persname>
79
+ <subject source="lcsh">Landscape architecture</subject>
80
+ <subject source="lcsh">Landscape architecture--United States--History</subject>
81
+ </controlaccess>
82
+ <dsc>
83
+ <c01 id="ref2" level="file">
84
+ <did>
85
+ <unittitle>Photographs, CDs of CAD drawings, sketches, prinouts of CAD drawings, newsclippings, brochures, pamphlets, and other records.</unittitle>
86
+ <container id="cid27000001" type="Carton" label="Mixed materials">1</container>
87
+ </did>
88
+ </c01>
89
+ <c01 id="ref3" level="file">
90
+ <did>
91
+ <unittitle>Photographs, CDs of CAD drawings, sketches, prinouts of CAD drawings, newsclippings, brochures, pamphlets, and other records.</unittitle>
92
+ <container id="cid27000002" type="Carton" label="Mixed materials">2</container>
93
+ </did>
94
+ </c01>
95
+ <c01 id="ref4" level="file">
96
+ <did>
97
+ <unittitle>Photographs, CDs of CAD drawings, sketches, prinouts of CAD drawings, newsclippings, brochures, pamphlets, and other records.</unittitle>
98
+ <container id="cid27000003" type="Carton" label="Mixed materials">3</container>
99
+ </did>
100
+ </c01>
101
+ <c01 id="ref15" level="file">
102
+ <did>
103
+ <unittitle>Photographic printouts</unittitle>
104
+ <container id="cid27167001" type="flatbox" label="Mixed materials">4</container>
105
+ </did>
106
+ </c01>
107
+ <c01 id="ref5" level="file">
108
+ <did>
109
+ <unittitle>Drawings of landscape architecture plans</unittitle>
110
+ <container id="cid27000010" type="tube" label="Mixed materials">54</container>
111
+ <container id="cid27000011" type="tube" label="Mixed materials">53</container>
112
+ <container id="cid27000008" type="tube" label="Mixed materials">56</container>
113
+ <container id="cid27000009" type="tube" label="Mixed materials">55</container>
114
+ <container id="cid27000014" type="tube" label="Mixed materials">50</container>
115
+ <container id="cid27000012" type="tube" label="Mixed materials">52</container>
116
+ <container id="cid27000013" type="tube" label="Mixed materials">51</container>
117
+ <container id="cid27000006" type="tube" label="Mixed materials">58</container>
118
+ <container id="cid27000007" type="tube" label="Mixed materials">57</container>
119
+ <container id="cid27000004" type="tube" label="Mixed materials">60</container>
120
+ <container id="cid27000005" type="tube" label="Mixed materials">59</container>
121
+ </did>
122
+ </c01>
123
+ <c01 id="ref6" level="file">
124
+ <did>
125
+ <unittitle>Drawings of landscape architecture plans and photographic printouts</unittitle>
126
+ <container id="cid27000019" type="flatfolder" label="Mixed materials">3</container>
127
+ <container id="cid27000018" type="flatfolder" label="Mixed materials">4</container>
128
+ <container id="cid27000017" type="flatfolder" label="Mixed materials">5</container>
129
+ <container id="cid27000016" type="flatfolder" label="Mixed materials">6</container>
130
+ <container id="cid27000021" type="flatfolder" label="Mixed materials">1</container>
131
+ <container id="cid27000020" type="flatfolder" label="Mixed materials">2</container>
132
+ </did>
133
+ </c01>
134
+ <c01 id="ref16" level="file">
135
+ <did>
136
+ <unittitle>Chesebrough Ponds - Trumbull</unittitle>
137
+ <container id="cid27509002" type="tube" label="Mixed materials">1</container>
138
+ </did>
139
+ </c01>
140
+
141
+ <c01 id="ref22" level="file">
142
+ <did>
143
+ <unittitle>David Berman, Stamford, Conn.</unittitle>
144
+ <container id="cid27509007" type="tube" label="Mixed materials">1</container>
145
+ <unitdate normal="1973/1973">1973</unitdate>
146
+ </did>
147
+ </c01>
148
+ <c01 id="ref23" level="file">
149
+ <did>
150
+ <unittitle>Donald F. Liebert, Nanuet, N.Y.</unittitle>
151
+ <container id="cid27509008" type="tube" label="Mixed materials">1</container>
152
+ <unitdate normal="1969/1969">1969</unitdate>
153
+ </did>
154
+ </c01>
155
+ </dsc>
156
+ </archdesc>
157
+ </ead>