stash-wrapper 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/lib/stash/wrapper/module_info.rb +1 -1
- data/lib/stash/wrapper/stash_wrapper.rb +5 -0
- data/spec/unit/stash/wrapper/stash_wrapper_spec.rb +80 -53
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b52a64485d0cc1f2d2a166a9c6ad20705eeaea
|
4
|
+
data.tar.gz: 36d2a6e3328c52ef4ec7d8649196d2aa4a2b4d11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ca5349052d42d20eaa529221306c313172629962801a950ba54fefa2ec302dfd763214364627d4e3dba25409e821887177d507582f1b6ca560cc4f0e167ef79
|
7
|
+
data.tar.gz: 452d94d172643e0b6a75f45a00c2b5bb7910b89e34d698126512772a7abb2c377335a37f52ade374bd696f1dc32883eecb1eef051d12f29d75ae0023642dfd30
|
data/CHANGES.md
CHANGED
@@ -90,6 +90,11 @@ module Stash
|
|
90
90
|
stash_administrative.inventory
|
91
91
|
end
|
92
92
|
|
93
|
+
def file_names
|
94
|
+
inv = inventory
|
95
|
+
inv ? inv.files.map(&:pathname) : []
|
96
|
+
end
|
97
|
+
|
93
98
|
# Overrides `XML::Mapping#pre_save` to set the XML namespace and schema location.
|
94
99
|
def pre_save(options = { mapping: :_default })
|
95
100
|
xml = super(options)
|
@@ -25,11 +25,10 @@ module Stash
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '#
|
28
|
+
describe '#parse_xml' do
|
29
29
|
it 'parses an XML file' do
|
30
30
|
data = File.read('spec/data/wrapper/wrapper-1.xml')
|
31
|
-
|
32
|
-
wrapper = StashWrapper.load_from_xml(xml)
|
31
|
+
wrapper = StashWrapper.parse_xml(data)
|
33
32
|
|
34
33
|
id = wrapper.identifier
|
35
34
|
expect(id.type).to eq(IdentifierType::DOI)
|
@@ -95,13 +94,25 @@ module Stash
|
|
95
94
|
|
96
95
|
expect(desc_elem).to be_xml(expected_xml)
|
97
96
|
end
|
97
|
+
|
98
|
+
it 'reads a Merritt OAI response' do
|
99
|
+
xml_str = File.read('spec/data/wrapper/mrtoai-wrapper.xml')
|
100
|
+
wrapper = StashWrapper.parse_xml(xml_str)
|
101
|
+
|
102
|
+
expect(wrapper.id_value).to eq('10.21271/wxy1000199')
|
103
|
+
expect(wrapper.version_number).to eq(1)
|
104
|
+
expect(wrapper.version_date).to eq(Date.new(2012, 8, 17))
|
105
|
+
expect(wrapper.license_name).to eq('Creative Commons Attribution 4.0 International (CC-BY)')
|
106
|
+
expect(wrapper.license_uri).to eq(URI('https://creativecommons.org/licenses/by/4.0/legalcode'))
|
107
|
+
expect(wrapper.embargo_type).to eq(EmbargoType::NONE)
|
108
|
+
expect(wrapper.embargo_end_date).to eq(Date.new(2012, 8, 17))
|
109
|
+
end
|
98
110
|
end
|
99
111
|
|
100
112
|
describe 'convenience accessors' do
|
101
113
|
it 'evades the law of Demeter' do
|
102
114
|
data = File.read('spec/data/wrapper/wrapper-1.xml')
|
103
|
-
|
104
|
-
wrapper = StashWrapper.load_from_xml(xml)
|
115
|
+
wrapper = StashWrapper.parse_xml(data)
|
105
116
|
|
106
117
|
expect(wrapper.id_value).to eq('10.12345/1234567890')
|
107
118
|
expect(wrapper.version_number).to eq(1)
|
@@ -119,34 +130,50 @@ module Stash
|
|
119
130
|
expect(file.size_bytes).to eq(12_345_678)
|
120
131
|
expect(file.mime_type).to eq(MIME::Type.new('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))
|
121
132
|
end
|
122
|
-
end
|
123
133
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
134
|
+
describe '#file_names' do
|
135
|
+
it 'lists the file names' do
|
136
|
+
data = File.read('spec/data/wrapper/wrapper-2.xml')
|
137
|
+
wrapper = StashWrapper.parse_xml(data)
|
138
|
+
|
139
|
+
expected = %w(
|
140
|
+
HSRC_MasterSampleII.dat
|
141
|
+
HSRC_MasterSampleII.csv
|
142
|
+
HSRC_MasterSampleII.sas7bdat
|
143
|
+
formats.sas7bcat
|
144
|
+
HSRC_MasterSampleII.sas
|
145
|
+
HSRC_MasterSampleII.sav
|
146
|
+
HSRC_MasterSampleII.sps
|
147
|
+
HSRC_MasterSampleII.dta
|
148
|
+
HSRC_MasterSampleII.dct
|
149
|
+
HSRC_MasterSampleII.do
|
150
|
+
)
|
151
|
+
expect(wrapper.file_names).to eq(expected)
|
152
|
+
end
|
128
153
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
154
|
+
it 'returns an empty array for an empty inventory' do
|
155
|
+
wrapper = StashWrapper.new(
|
156
|
+
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
157
|
+
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
158
|
+
license: License::CC_BY,
|
159
|
+
descriptive_elements: []
|
160
|
+
)
|
161
|
+
expect(wrapper.file_names).to eq([])
|
162
|
+
end
|
136
163
|
end
|
137
164
|
end
|
138
165
|
|
139
166
|
describe '#initialize' do
|
140
167
|
it 'defaults to no embargo' do
|
141
168
|
wrapper = StashWrapper.new(
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
169
|
+
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
170
|
+
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
171
|
+
license: License::CC_BY,
|
172
|
+
inventory: Inventory.new(
|
173
|
+
files: [
|
174
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
|
175
|
+
]),
|
176
|
+
descriptive_elements: []
|
150
177
|
)
|
151
178
|
embargo = wrapper.embargo
|
152
179
|
expect(embargo).to be_an(Embargo)
|
@@ -163,16 +190,16 @@ module Stash
|
|
163
190
|
describe 'namespace handling' do
|
164
191
|
before :each do
|
165
192
|
wrapper = StashWrapper.new(
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
193
|
+
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
194
|
+
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
195
|
+
license: License::CC_BY,
|
196
|
+
embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2014, 8, 18), end_date: Date.new(2013, 8, 18)),
|
197
|
+
inventory: Inventory.new(
|
198
|
+
files: [
|
199
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
|
200
|
+
]),
|
201
|
+
# Note: the recursive asserts only work because descriptive_elements is empty
|
202
|
+
descriptive_elements: []
|
176
203
|
)
|
177
204
|
@wrapper_xml = wrapper.save_to_xml
|
178
205
|
end
|
@@ -222,24 +249,24 @@ module Stash
|
|
222
249
|
payload_xml = REXML::Document.new(payload).root
|
223
250
|
|
224
251
|
wrapper = StashWrapper.new(
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
252
|
+
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
253
|
+
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
254
|
+
license: License::CC_BY,
|
255
|
+
embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2014, 8, 18), end_date: Date.new(2013, 8, 18)),
|
256
|
+
inventory: Inventory.new(
|
257
|
+
files: [
|
258
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain'),
|
259
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.csv', size_bytes: 67_890, mime_type: 'text/csv'),
|
260
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.sas7bdat', size_bytes: 123_456, mime_type: 'application/x-sas-data'),
|
261
|
+
StashFile.new(pathname: 'formats.sas7bcat', size_bytes: 78_910, mime_type: 'application/x-sas-catalog'),
|
262
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.sas', size_bytes: 11_121, mime_type: 'application/x-sas'),
|
263
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.sav', size_bytes: 31_415, mime_type: 'application/x-sav'),
|
264
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.sps', size_bytes: 16_171, mime_type: 'application/x-spss'),
|
265
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dta', size_bytes: 81_920, mime_type: 'application/x-dta'),
|
266
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dct', size_bytes: 212_223, mime_type: 'application/x-dct'),
|
267
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.do', size_bytes: 242_526, mime_type: 'application/x-do')
|
268
|
+
]),
|
269
|
+
descriptive_elements: [payload_xml]
|
243
270
|
)
|
244
271
|
|
245
272
|
wrapper_xml = wrapper.save_to_xml
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typesafe_enum
|
@@ -209,7 +209,7 @@ files:
|
|
209
209
|
- spec/unit/stash/wrapper/stash_administrative_spec.rb
|
210
210
|
- spec/unit/stash/wrapper/stash_wrapper_spec.rb
|
211
211
|
- stash-wrapper.gemspec
|
212
|
-
homepage: http://github.com/
|
212
|
+
homepage: http://github.com/dmolesUC3/stash-wrapper
|
213
213
|
licenses:
|
214
214
|
- MIT
|
215
215
|
metadata: {}
|