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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffbc971060572311562d5cddea48605f7c6d152f
4
- data.tar.gz: 80c7a4e1e610b4f945dfded51cb3f6835362d62e
3
+ metadata.gz: b3b52a64485d0cc1f2d2a166a9c6ad20705eeaea
4
+ data.tar.gz: 36d2a6e3328c52ef4ec7d8649196d2aa4a2b4d11
5
5
  SHA512:
6
- metadata.gz: 692b374270d158d5e7c45fc3e7ca3b5fda1c43df8d465e28171977fd332063eb8264527eb245174719314b9be0393edc439d4c2f720fb0a3f1ccb5870486fd64
7
- data.tar.gz: c35a351a76d85e7f25d843a169fd7acc15a28a073f94eb23bd2c04e6afe01e05f16bea9e903d610cb3c4026c32554e725640a01ef20779dff88f2dd16a3f5098
6
+ metadata.gz: 7ca5349052d42d20eaa529221306c313172629962801a950ba54fefa2ec302dfd763214364627d4e3dba25409e821887177d507582f1b6ca560cc4f0e167ef79
7
+ data.tar.gz: 452d94d172643e0b6a75f45a00c2b5bb7910b89e34d698126512772a7abb2c377335a37f52ade374bd696f1dc32883eecb1eef051d12f29d75ae0023642dfd30
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.1.3 (19 April 2016)
2
+
3
+ - Add convenience method `StashWrapper.file_names` to return a list of filenames
4
+ from the inventory
5
+
1
6
  # 0.1.2 (31 March 2016)
2
7
 
3
8
  - Add convenience method `Embargo.none` to create a no-embargo embargo element
@@ -5,7 +5,7 @@ module Stash
5
5
  NAME = 'stash-wrapper'
6
6
 
7
7
  # The version of this gem
8
- VERSION = '0.1.2'
8
+ VERSION = '0.1.3'
9
9
 
10
10
  # The copyright notice for this gem
11
11
  COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'
@@ -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 '#load_from_xml' do
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
- xml = REXML::Document.new(data).root
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
- xml = REXML::Document.new(data).root
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
- 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)
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
- 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))
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
- identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
143
- version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
144
- license: License::CC_BY,
145
- inventory: Inventory.new(
146
- files: [
147
- StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
148
- ]),
149
- descriptive_elements: []
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
- identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
167
- version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
168
- license: License::CC_BY,
169
- embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2014, 8, 18), end_date: Date.new(2013, 8, 18)),
170
- inventory: Inventory.new(
171
- files: [
172
- StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
173
- ]),
174
- # Note: the recursive asserts only work because descriptive_elements is empty
175
- descriptive_elements: []
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
- identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
226
- version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
227
- license: License::CC_BY,
228
- embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2014, 8, 18), end_date: Date.new(2013, 8, 18)),
229
- inventory: Inventory.new(
230
- files: [
231
- StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain'),
232
- StashFile.new(pathname: 'HSRC_MasterSampleII.csv', size_bytes: 67_890, mime_type: 'text/csv'),
233
- StashFile.new(pathname: 'HSRC_MasterSampleII.sas7bdat', size_bytes: 123_456, mime_type: 'application/x-sas-data'),
234
- StashFile.new(pathname: 'formats.sas7bcat', size_bytes: 78_910, mime_type: 'application/x-sas-catalog'),
235
- StashFile.new(pathname: 'HSRC_MasterSampleII.sas', size_bytes: 11_121, mime_type: 'application/x-sas'),
236
- StashFile.new(pathname: 'HSRC_MasterSampleII.sav', size_bytes: 31_415, mime_type: 'application/x-sav'),
237
- StashFile.new(pathname: 'HSRC_MasterSampleII.sps', size_bytes: 16_171, mime_type: 'application/x-spss'),
238
- StashFile.new(pathname: 'HSRC_MasterSampleII.dta', size_bytes: 81_920, mime_type: 'application/x-dta'),
239
- StashFile.new(pathname: 'HSRC_MasterSampleII.dct', size_bytes: 212_223, mime_type: 'application/x-dct'),
240
- StashFile.new(pathname: 'HSRC_MasterSampleII.do', size_bytes: 242_526, mime_type: 'application/x-do')
241
- ]),
242
- descriptive_elements: [payload_xml]
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.2
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-01 00:00:00.000000000 Z
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/CDLUC3/stash-wrapper
212
+ homepage: http://github.com/dmolesUC3/stash-wrapper
213
213
  licenses:
214
214
  - MIT
215
215
  metadata: {}