stash-wrapper 0.1.1

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,164 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <st:stash_wrapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://dash.cdlib.org/stash_wrapper/ http://dash.cdlib.org/stash_wrapper/stash_wrapper.xsd"
4
+ xmlns:st="http://dash.cdlib.org/stash_wrapper/">
5
+ <st:identifier type="DOI">10.14749/1407399498</st:identifier>
6
+ <st:stash_administrative>
7
+ <st:version>
8
+ <st:version_number>1</st:version_number>
9
+ <st:date>2013-08-18Z</st:date>
10
+ <st:note>Sample wrapped Datacite document</st:note>
11
+ </st:version>
12
+ <st:license>
13
+ <st:name>Creative Commons Attribution 4.0 International (CC-BY)</st:name>
14
+ <st:uri>https://creativecommons.org/licenses/by/4.0/legalcode</st:uri>
15
+ </st:license>
16
+ <st:embargo>
17
+ <st:type>download</st:type>
18
+ <st:period>1 year</st:period>
19
+ <st:start>2014-08-18Z</st:start>
20
+ <st:end>2013-08-18Z</st:end>
21
+ </st:embargo>
22
+ <st:inventory num_files="10">
23
+ <st:file>
24
+ <st:pathname>HSRC_MasterSampleII.dat</st:pathname>
25
+ <st:size unit="B">12345</st:size>
26
+ <st:mime_type>text/plain</st:mime_type>
27
+ </st:file>
28
+ <st:file>
29
+ <st:pathname>HSRC_MasterSampleII.csv</st:pathname>
30
+ <st:size unit="B">67890</st:size>
31
+ <st:mime_type>text/csv</st:mime_type>
32
+ </st:file>
33
+ <st:file>
34
+ <st:pathname>HSRC_MasterSampleII.sas7bdat</st:pathname>
35
+ <st:size unit="B">123456</st:size>
36
+ <st:mime_type>application/x-sas-data</st:mime_type>
37
+ </st:file>
38
+ <st:file>
39
+ <st:pathname>formats.sas7bcat</st:pathname>
40
+ <st:size unit="B">78910</st:size>
41
+ <st:mime_type>application/x-sas-catalog</st:mime_type>
42
+ </st:file>
43
+ <st:file>
44
+ <st:pathname>HSRC_MasterSampleII.sas</st:pathname>
45
+ <st:size unit="B">11121</st:size>
46
+ <st:mime_type>application/x-sas</st:mime_type>
47
+ </st:file>
48
+ <st:file>
49
+ <st:pathname>HSRC_MasterSampleII.sav</st:pathname>
50
+ <st:size unit="B">31415</st:size>
51
+ <st:mime_type>application/x-sav</st:mime_type>
52
+ </st:file>
53
+ <st:file>
54
+ <st:pathname>HSRC_MasterSampleII.sps</st:pathname>
55
+ <st:size unit="B">16171</st:size>
56
+ <st:mime_type>application/x-spss</st:mime_type>
57
+ </st:file>
58
+ <st:file>
59
+ <st:pathname>HSRC_MasterSampleII.dta</st:pathname>
60
+ <st:size unit="B">81920</st:size>
61
+ <st:mime_type>application/x-dta</st:mime_type>
62
+ </st:file>
63
+ <st:file>
64
+ <st:pathname>HSRC_MasterSampleII.dct</st:pathname>
65
+ <st:size unit="B">212223</st:size>
66
+ <st:mime_type>application/x-dct</st:mime_type>
67
+ </st:file>
68
+ <st:file>
69
+ <st:pathname>HSRC_MasterSampleII.do</st:pathname>
70
+ <st:size unit="B">242526</st:size>
71
+ <st:mime_type>application/x-do</st:mime_type>
72
+ </st:file>
73
+ </st:inventory>
74
+ </st:stash_administrative>
75
+ <st:stash_descriptive>
76
+ <resource xmlns='http://datacite.org/schema/kernel-3' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
77
+ xsi:schemaLocation='http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd'>
78
+ <identifier identifierType='DOI'>10.14749/1407399498</identifier>
79
+ <creators>
80
+ <creator>
81
+ <creatorName>Zuma, Khangelani</creatorName>
82
+ </creator>
83
+ <creator>
84
+ <creatorName>Human Sciences Research Council</creatorName>
85
+ </creator>
86
+ </creators>
87
+ <titles>
88
+ <title xml:lang='en'>HSRC Master Sample II</title>
89
+ </titles>
90
+ <publisher>HSRC - Human Science Research Council SA</publisher>
91
+ <publicationYear>2014</publicationYear>
92
+ <contributors>
93
+ <contributor contributorType='Distributor'>
94
+ <contributorName>Human Sciences Research Council</contributorName>
95
+ </contributor>
96
+ <contributor contributorType='Funder'>
97
+ <contributorName>Human Sciences Research Council</contributorName>
98
+ </contributor>
99
+ <contributor contributorType='RightsHolder'>
100
+ <contributorName>Human Sciences Research Council</contributorName>
101
+ </contributor>
102
+ </contributors>
103
+ <language>eng</language>
104
+ <resourceType resourceTypeGeneral='Dataset'/>
105
+ <version>1.0</version>
106
+ <rightsList>
107
+ <rights>
108
+ By accessing the data, you give assurance that The data and documentation will not be duplicated, redistributed or sold without prior approval from
109
+ the rights holder. The data will be used for scientific research or educational purposes only. The data will only be used for the specified
110
+ purpose. If it is used for another purpose the additional purpose will be registered. Redundant data files will be destroyed. The confidentiality of
111
+ individuals/organisations in the data will be preserved at all times. No attempt will be made to obtain or derive information from the data to
112
+ identify individuals/organisations. The HSRC will be acknowledged in all published and unpublished works based on the data according to the provided
113
+ citation. The HSRC will be informed of any books, articles, conference papers, theses, dissertations, reports or other publications resulting from
114
+ work based in whole or in part on the data and documentation. For archiving and bibliographic purposes an electronic copy of all reports and
115
+ publications based on the requested data will be sent to the HSRC. To offer for deposit into the HSRC Data Collection any new data sets which have
116
+ been derived from or which have been created by the combination of the data supplied with other data. The data team bears no responsibility for use of
117
+ the data or for interpretations or inferences based upon such uses. Failure to comply with the End User License may result in sanctions being imposed.
118
+ </rights>
119
+ </rightsList>
120
+ <descriptions>
121
+ <description descriptionType='Abstract' xml:lang='en'>
122
+ &lt;p&gt; The 2005 HSRC Master Sample was used for SABSSM 2008 and 2012, the SANHANES study in 2012 and SASAS 2007-2010 (adjacent EAs) to obtain an
123
+ understanding of geographical spread of HIV/AIDS, perceptions and attitudes of people and other health related studies over time.&lt;/p&gt;
124
+ </description>
125
+ <description descriptionType='Abstract' xml:lang='en'>
126
+ &lt;p&gt; A sample can be defined as a subset containing the characteristics of a larger population. Samples are used in statistical testing when
127
+ population sizes are too large for the test to include all possible members or observations. A sample should represent the whole population and not
128
+ reflect bias toward a specific attribute.[1]&lt;/p&gt; &lt;p&gt; One of the most crucial aspects of sample design in household surveys is its
129
+ frame. The sampling frame has significant implications on the cost and the quality of any survey, household or otherwise.[2]&lt;/p&gt; &lt;p&gt; The
130
+ sampling frame .... in a household survey must cover the entire target population. When that frame is used for multiple surveys or multiple rounds of
131
+ the same survey it is known as a master sample frame or .... master sample.[3]&lt;/p&gt; &lt;p&gt; A master sample is a sample drawn from a population
132
+ for use on a number of future occasions, so as to avoid ad hoc sampling on each occasion. Sometimes the master sample is large and subsequent
133
+ inquiries are based on a sub-sample from it.[4]&lt;/p&gt; &lt;p&gt; The HSRC compiles master samples in order to construct samples for various HSRC
134
+ research studies. The 2005 HSRC Master Sample was used for SABSSM 2008 and 2012, SASAS 2007-2010 and the SANHANES study in 2012 to obtain an
135
+ understanding of geographical spread of HIV/AIDS, perceptions and attitudes of people and other health related studies over time.&lt;/p&gt; &lt;p&gt;
136
+ The 2005 HSRC Master Sample was created in the following way:&lt;/p&gt; &lt;p&gt; South Africa was delineated into EAs according to municipality and
137
+ province. Municipal boundaries were obtained from the Municipal Demarcation Board. An Enumeration area (EA) is the smallest geographical unit (piece
138
+ of land) into which the country is divided for census or survey enumeration.[5] The concepts and definitions of terms used for Census 2001 comply in
139
+ most instances with United Nations standards for censuses.&lt;/p&gt; &lt;p&gt; A total of 1,000 census enumeration areas (EAs) from the 2001
140
+ population census were randomly selected using probability proportional to size and stratified by province, locality type and race in urban areas from
141
+ a database of 80 787 EAs that were mapped using aerial photography to develop an HSRC master sample for selecting households.&lt;/p&gt; &lt;p&gt; The
142
+ ideal frame would be complete with respect to the target population if all of its members (the universe) are covered by the frame.&lt;/p&gt; &lt;p&gt;
143
+ Ideal characteristics of a master sample:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; The master frame should be as complete, accurate and current as
144
+ practicable.&lt;/li&gt; &lt;li&gt; A master sample frame for household surveys is typically developed from the most recent census, just as a regular
145
+ sample frame is.&lt;/li&gt; &lt;li&gt; Because the master frame may be used during an entire intercensal (between census) period, however, it will
146
+ usually require periodic and regular updating such as every 2-3 years.&lt;/li&gt; &lt;li&gt; This is in contrast to a regular frame which is more
147
+ likely to be up-dated on an ad hoc basis and only when a particular survey is being planned[6]&lt;/li&gt; &lt;/ul&gt; &lt;p&gt; [1]
148
+ http://www.investopedia.com/terms/s/sample.asp&lt;/p&gt; &lt;p&gt; [2]
149
+ http://unstats.un.org/unsd/demographic/meetings/egm/sampling_1203/docs/no_3.pdf&lt;/p&gt; &lt;p&gt; [3]
150
+ http://unstats.un.org/unsd/demographic/meetings/egm/sampling_1203/docs/no_3.pdf&lt;/p&gt; &lt;p&gt; [4] A Dictionary of Statistical Terms, 5th
151
+ edition, prepared for the International Statistical Institute by F.H.C. Marriott. Published for the International Statistical Institute by Longman
152
+ Scientific and Technical. http://stats.oecd.org/glossary/detail.asp?ID=3708&lt;/p&gt; &lt;p&gt; [5]
153
+ http://africageodownloads.info/128_mokgokolo.pdf&lt;/p&gt; &lt;p&gt; [6]
154
+ http://unstats.un.org/unsd/demographic/meetings/egm/sampling_1203/docs/no_3.pdf&lt;/p&gt;
155
+ </description>
156
+ </descriptions>
157
+ <geoLocations>
158
+ <geoLocation>
159
+ <geoLocationPlace>National - all 9 provinces</geoLocationPlace>
160
+ </geoLocation>
161
+ </geoLocations>
162
+ </resource>
163
+ </st:stash_descriptive>
164
+ </st:stash_wrapper>
@@ -0,0 +1,69 @@
1
+ require 'rspec/expectations'
2
+ require 'equivalent-xml'
3
+
4
+ RSpec::Matchers.define :be_xml do |expected|
5
+
6
+ def to_nokogiri(xml)
7
+ return nil unless xml
8
+ case xml
9
+ when Nokogiri::XML::Element
10
+ xml
11
+ when Nokogiri::XML::Document
12
+ xml.root
13
+ when String
14
+ to_nokogiri(Nokogiri::XML(xml))
15
+ when REXML::Element
16
+ to_nokogiri(xml.to_s)
17
+ else
18
+ fail "be_xml() expected XML, got #{xml.class}"
19
+ end
20
+ end
21
+
22
+ def to_pretty(nokogiri)
23
+ return nil unless nokogiri
24
+ out = StringIO.new
25
+ save_options = Nokogiri::XML::Node::SaveOptions::FORMAT | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
26
+ nokogiri.write_xml_to(out, encoding: 'UTF-8', indent: 2, save_with: save_options)
27
+ out.string
28
+ end
29
+
30
+ match do |actual|
31
+ expected_xml = to_nokogiri(expected) || fail("expected value #{expected} does not appear to be XML")
32
+ actual_xml = to_nokogiri(actual)
33
+
34
+ EquivalentXml.equivalent?(expected_xml, actual_xml, element_order: false, normalize_whitespace: true)
35
+ end
36
+
37
+ failure_message do |actual|
38
+ expected_string = to_pretty(to_nokogiri(expected))
39
+ actual_string = to_pretty(to_nokogiri(actual)) || actual
40
+ "expected XML:\n#{expected_string}\n\nbut was:\n#{actual_string}"
41
+ end
42
+
43
+ failure_message_when_negated do |actual|
44
+ actual_xml = to_element(actual) || actual
45
+ "expected not to get XML:\n\t#{actual_xml}"
46
+ end
47
+ end
48
+
49
+ RSpec::Matchers.define :be_time do |expected|
50
+
51
+ def to_string(time)
52
+ time.is_a?(Time) ? time.utc.round(2).iso8601(2) : time.to_s
53
+ end
54
+
55
+ match do |actual|
56
+ if expected
57
+ fail "Expected value #{expected} is not a Time" unless expected.is_a?(Time)
58
+ actual.is_a?(Time) && (to_string(expected) == to_string(actual))
59
+ else
60
+ return actual.nil?
61
+ end
62
+ end
63
+
64
+ failure_message do |actual|
65
+ expected_str = to_string(expected)
66
+ actual_str = to_string(actual)
67
+ "expected time:\n#{expected_str}\n\nbut was:\n#{actual_str}"
68
+ end
69
+ end
@@ -0,0 +1,31 @@
1
+ # ------------------------------------------------------------
2
+ # SimpleCov setup
3
+
4
+ if ENV['COVERAGE']
5
+ require 'simplecov'
6
+ require 'simplecov-console'
7
+
8
+ SimpleCov.minimum_coverage 100
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
12
+ SimpleCov::Formatter::HTMLFormatter,
13
+ SimpleCov::Formatter::Console,
14
+ ]
15
+ end
16
+ end
17
+
18
+ # ------------------------------------------------------------
19
+ # Rspec configuration
20
+
21
+ RSpec.configure do |config|
22
+ config.raise_errors_for_deprecations!
23
+ config.mock_with :rspec
24
+ end
25
+
26
+ require 'rspec_custom_matchers'
27
+
28
+ # ------------------------------------------------------------
29
+ # Stash::Wrapper
30
+
31
+ require 'stash/wrapper'
@@ -0,0 +1,239 @@
1
+ require 'spec_helper'
2
+
3
+ require 'nokogiri'
4
+ require 'rexml/element'
5
+
6
+ module Stash
7
+ module Wrapper
8
+ describe StashWrapper do
9
+ describe 'stash_wrapper.xsd' do
10
+ it 'is valid' do
11
+ schema = Nokogiri::XML::Schema(File.read('spec/data/wrapper/stash_wrapper.xsd'))
12
+ document = Nokogiri::XML(File.read('spec/data/wrapper/wrapper-1.xml'))
13
+ errors = schema.validate(document)
14
+ expect(errors.empty?).to be true
15
+ end
16
+
17
+ it 'validates a document' do
18
+ schema = Nokogiri::XML::Schema(File.read('spec/data/wrapper/stash_wrapper.xsd'))
19
+ document = Nokogiri::XML(File.read('spec/data/wrapper/wrapper-2.xml'))
20
+ errors = schema.validate(document)
21
+ errors.each do |e|
22
+ puts e
23
+ end
24
+ expect(errors.empty?).to be true
25
+ end
26
+ end
27
+
28
+ describe '#load_from_xml' do
29
+ it 'parses an XML file' do
30
+ data = File.read('spec/data/wrapper/wrapper-1.xml')
31
+ xml = REXML::Document.new(data).root
32
+ wrapper = StashWrapper.load_from_xml(xml)
33
+
34
+ id = wrapper.identifier
35
+ expect(id.type).to eq(IdentifierType::DOI)
36
+ expect(id.value).to eq('10.12345/1234567890')
37
+
38
+ admin = wrapper.stash_administrative
39
+
40
+ version = admin.version
41
+ expect(version.version_number).to eq(1)
42
+ expect(version.date).to eq(Date.new(2015, 9, 8))
43
+
44
+ license = admin.license
45
+ expect(license.name).to eq('Creative Commons Attribution 4.0 International (CC-BY)')
46
+ expect(license.uri).to eq(URI('https://creativecommons.org/licenses/by/4.0/legalcode'))
47
+
48
+ embargo = admin.embargo
49
+ expect(embargo.type).to eq(EmbargoType::DOWNLOAD)
50
+ expect(embargo.period).to eq('6 months')
51
+ expect(embargo.start_date).to eq(Date.new(2015, 9, 8))
52
+ expect(embargo.end_date).to eq(Date.new(2016, 3, 7))
53
+
54
+ inventory = admin.inventory
55
+ expect(inventory.num_files).to eq(1)
56
+ expect(inventory.files.size).to eq(1)
57
+
58
+ file = inventory.files[0]
59
+ expect(file.pathname).to eq('mydata.xlsx')
60
+ expect(file.size_bytes).to eq(12_345_678)
61
+ expect(file.mime_type).to eq(MIME::Type.new('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))
62
+
63
+ descriptive = wrapper.stash_descriptive
64
+ expect(descriptive).to be_an(Array)
65
+ expect(descriptive.size).to eq(1)
66
+ desc_elem = descriptive[0]
67
+ expect(desc_elem).to be_an(REXML::Element)
68
+
69
+ expected_xml =
70
+ '<dcs:resource xmlns:dcs="http://datacite.org/schema/kernel-3"
71
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
72
+ xsi:schemaLocation="http://datacite.org/schema/kernel-3
73
+ http://schema.datacite.org/meta/kernel-3/metadata.xsd">
74
+ <dcs:identifier identifierType="DOI">10.12345/1234567890</dcs:identifier>
75
+ <dcs:creators>
76
+ <dcs:creator>
77
+ <dcs:creatorName>Abrams, Stephen</dcs:creatorName>
78
+ </dcs:creator>
79
+ </dcs:creators>
80
+ <dcs:titles>
81
+ <dcs:title>My dataset</dcs:title>
82
+ </dcs:titles>
83
+ <dcs:publisher>UC Office of the President</dcs:publisher>
84
+ <dcs:publicationYear>2016</dcs:publicationYear>
85
+ <dcs:subjects>
86
+ <dcs:subject>Data literacy</dcs:subject>
87
+ </dcs:subjects>
88
+ <dcs:resourceType resourceTypeGeneral="Dataset">Spreadsheet</dcs:resourceType>
89
+ <dcs:descriptions>
90
+ <dcs:description descriptionType="Abstract">
91
+ Lorum ipsum.
92
+ </dcs:description>
93
+ </dcs:descriptions>
94
+ </dcs:resource>'
95
+
96
+ expect(desc_elem).to be_xml(expected_xml)
97
+ end
98
+ end
99
+
100
+ describe 'convenience accessors' do
101
+ it 'evades the law of Demeter' do
102
+ data = File.read('spec/data/wrapper/wrapper-1.xml')
103
+ xml = REXML::Document.new(data).root
104
+ wrapper = StashWrapper.load_from_xml(xml)
105
+
106
+ expect(wrapper.id_value).to eq('10.12345/1234567890')
107
+ expect(wrapper.version_number).to eq(1)
108
+ expect(wrapper.version_date).to eq(Date.new(2015, 9, 8))
109
+ expect(wrapper.license_name).to eq('Creative Commons Attribution 4.0 International (CC-BY)')
110
+ expect(wrapper.license_uri).to eq(URI('https://creativecommons.org/licenses/by/4.0/legalcode'))
111
+ expect(wrapper.embargo_type).to eq(EmbargoType::DOWNLOAD)
112
+ expect(wrapper.embargo_end_date).to eq(Date.new(2016, 3, 7))
113
+
114
+ inventory = wrapper.inventory
115
+ expect(inventory.num_files).to eq(1)
116
+ expect(inventory.files.size).to eq(1)
117
+ file = inventory.files[0]
118
+ expect(file.pathname).to eq('mydata.xlsx')
119
+ expect(file.size_bytes).to eq(12_345_678)
120
+ expect(file.mime_type).to eq(MIME::Type.new('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))
121
+ end
122
+ end
123
+
124
+ describe '#parse_xml' do
125
+ it 'reads a Merritt OAI response' do
126
+ xml_str = File.read('spec/data/wrapper/mrtoai-wrapper.xml')
127
+ wrapper = StashWrapper.parse_xml(xml_str)
128
+
129
+ expect(wrapper.id_value).to eq('10.21271/wxy1000199')
130
+ expect(wrapper.version_number).to eq(1)
131
+ expect(wrapper.version_date).to eq(Date.new(2012, 8, 17))
132
+ expect(wrapper.license_name).to eq('Creative Commons Attribution 4.0 International (CC-BY)')
133
+ expect(wrapper.license_uri).to eq(URI('https://creativecommons.org/licenses/by/4.0/legalcode'))
134
+ expect(wrapper.embargo_type).to eq(EmbargoType::NONE)
135
+ expect(wrapper.embargo_end_date).to eq(Date.new(2012, 8, 17))
136
+ end
137
+ end
138
+
139
+ describe '#save_to_xml' do
140
+
141
+ describe 'namespace handling' do
142
+ before :each do
143
+ wrapper = StashWrapper.new(
144
+ identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
145
+ version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
146
+ license: License::CC_BY,
147
+ embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2014, 8, 18), end_date: Date.new(2013, 8, 18)),
148
+ inventory: Inventory.new(
149
+ files: [
150
+ StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
151
+ ]),
152
+ # Note: the recursive asserts only work because descriptive_elements is empty
153
+ descriptive_elements: []
154
+ )
155
+ @wrapper_xml = wrapper.save_to_xml
156
+ end
157
+
158
+ it 'sets the correct namespace' do
159
+ assert_st = lambda do |elem|
160
+ actual = elem.namespace
161
+ expected = StashWrapper::NAMESPACE
162
+ expect(actual).to eq(expected), "expected '#{expected}', got '#{actual}': #{elem}"
163
+ elem.each_element { |e| assert_st.call(e) }
164
+ end
165
+ assert_st.call(@wrapper_xml.root)
166
+ end
167
+
168
+ it 'sets the correct namespace prefix' do
169
+ assert_st = lambda do |elem|
170
+ actual = elem.prefix
171
+ expected = StashWrapper::NAMESPACE_PREFIX
172
+ expect(actual).to eq(expected), "expected '#{expected}', got '#{actual}': #{elem}"
173
+ elem.each_element { |e| assert_st.call(e) }
174
+ end
175
+ assert_st.call(@wrapper_xml.root)
176
+ end
177
+
178
+ it 'maps the namespace to the prefix' do
179
+ assert_st = lambda do |elem|
180
+ actual = elem.namespace(StashWrapper::NAMESPACE_PREFIX)
181
+ expected = StashWrapper::NAMESPACE
182
+ expect(actual).to eq(expected), "expected '#{expected}', got '#{actual}': #{elem}"
183
+ elem.each_element { |e| assert_st.call(e) }
184
+ end
185
+ assert_st.call(@wrapper_xml.root)
186
+ end
187
+
188
+ it 'includes the prefix in the name' do
189
+ assert_st = lambda do |elem|
190
+ expect(elem.to_s).to start_with("<#{StashWrapper::NAMESPACE_PREFIX}:")
191
+ elem.each_element { |e| assert_st.call(e) }
192
+ end
193
+ assert_st.call(@wrapper_xml.root)
194
+ end
195
+ end
196
+
197
+ it 'maps to XML' do
198
+
199
+ payload = File.read('spec/data/wrapper/wrapper-2-payload.xml')
200
+ payload_xml = REXML::Document.new(payload).root
201
+
202
+ wrapper = StashWrapper.new(
203
+ identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
204
+ version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
205
+ license: License::CC_BY,
206
+ embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2014, 8, 18), end_date: Date.new(2013, 8, 18)),
207
+ inventory: Inventory.new(
208
+ files: [
209
+ StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain'),
210
+ StashFile.new(pathname: 'HSRC_MasterSampleII.csv', size_bytes: 67_890, mime_type: 'text/csv'),
211
+ StashFile.new(pathname: 'HSRC_MasterSampleII.sas7bdat', size_bytes: 123_456, mime_type: 'application/x-sas-data'),
212
+ StashFile.new(pathname: 'formats.sas7bcat', size_bytes: 78_910, mime_type: 'application/x-sas-catalog'),
213
+ StashFile.new(pathname: 'HSRC_MasterSampleII.sas', size_bytes: 11_121, mime_type: 'application/x-sas'),
214
+ StashFile.new(pathname: 'HSRC_MasterSampleII.sav', size_bytes: 31_415, mime_type: 'application/x-sav'),
215
+ StashFile.new(pathname: 'HSRC_MasterSampleII.sps', size_bytes: 16_171, mime_type: 'application/x-spss'),
216
+ StashFile.new(pathname: 'HSRC_MasterSampleII.dta', size_bytes: 81_920, mime_type: 'application/x-dta'),
217
+ StashFile.new(pathname: 'HSRC_MasterSampleII.dct', size_bytes: 212_223, mime_type: 'application/x-dct'),
218
+ StashFile.new(pathname: 'HSRC_MasterSampleII.do', size_bytes: 242_526, mime_type: 'application/x-do')
219
+ ]),
220
+ descriptive_elements: [payload_xml]
221
+ )
222
+
223
+ wrapper_xml = wrapper.save_to_xml
224
+
225
+ # File.open('spec/data/wrapper/wrapper-2-actual.xml', 'w') do |file|
226
+ # formatter = REXML::Formatters::Pretty.new
227
+ # formatter.width = 200
228
+ # formatter.compact = true
229
+ # file.write(formatter.write(wrapper_xml, ''))
230
+ # end
231
+
232
+ expected_xml = File.read('spec/data/wrapper/wrapper-2.xml')
233
+ expect(wrapper_xml).to be_xml(expected_xml)
234
+ end
235
+ end
236
+
237
+ end
238
+ end
239
+ end