hydra-pbcore 2.2.0rc1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,9 +5,11 @@
5
5
  .config
6
6
  .yardoc
7
7
  .rvmrc
8
+ .ruby-version
8
9
  Gemfile.lock
9
10
  InstalledFiles
10
11
  _yardoc
12
+ bin
11
13
  coverage
12
14
  doc/
13
15
  lib/bundler/man
data/hydra-pbcore.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  # Dependencies
20
20
  gem.add_dependency('active-fedora')
21
+ gem.add_dependency('solrizer', '< 3.0.0')
21
22
  gem.add_development_dependency('yard')
22
23
  gem.add_development_dependency('redcarpet')
23
24
  # For Development
data/lib/hydra-pbcore.rb CHANGED
@@ -66,6 +66,14 @@ module HydraPbcore
66
66
  Nokogiri::XML(xml)
67
67
  end
68
68
 
69
+ # Validates a supplied xml document against the PBCore schema. This differs from
70
+ # HydraPbcore::Methods.valid? which validates self, instead of the supplied argument.
71
+ # Argument must be a Nokogiri::XML::Document.
72
+ def self.is_valid? xml
73
+ xsd = Nokogiri::XML::Schema(open("http://pbcore.org/xsd/pbcore-2.0.xsd"))
74
+ xsd.validate(xml)
75
+ end
76
+
69
77
  autoload :Mapper
70
78
  autoload :Methods
71
79
  autoload :Conversions
@@ -4,18 +4,37 @@ module HydraPbcore::Methods
4
4
  self.find_by_terms(type.to_sym).slice(index.to_i).remove
5
5
  end
6
6
 
7
- # Returns a new Nokogiri::XML object with the contents of self reordered and repackaged as a
8
- # valid pbcore xml document.
7
+ # Returns a new Nokogiri::XML object with the contents of self, plus any additional instanstations,
8
+ # reordered and repackaged as a valid pbcore xml document.
9
9
  #
10
10
  # The original xml from the datastream is copied to a new Nokogiri object, then each node
11
- # is added--in correct order--to a new blank, valid pbcore xml document.
12
- def to_pbcore_xml
11
+ # is added--in correct order--to a new blank, valid pbcore xml document. If additional
12
+ # instantiations are passed in as an array, those are correctly reordered as well, and
13
+ # included in the document
14
+ def to_pbcore_xml included_instantiations = Array.new, instantiations = Array.new
15
+
16
+ # Reorder any included instantations
17
+ included_instantiations.each do |i|
18
+ original_inst = Nokogiri::XML(i.to_xml)
19
+ new_inst = Nokogiri::XML("<pbcoreInstantiation/>")
20
+ HydraPbcore::InstantiationNodes.each do |node|
21
+ original_inst.search(node).each do |n|
22
+ new_inst.root.add_child(n)
23
+ end
24
+ end
25
+ instantiations << new_inst
26
+ end
27
+
28
+ # Reorder the document
13
29
  original = Nokogiri::XML(self.to_xml)
14
30
  new_doc = HydraPbcore.blank
15
31
  HydraPbcore::DocumentNodes.each do |node|
16
32
  original.search(node).each do |n|
17
33
  new_doc.root.add_child(n)
18
34
  end
35
+ if node.match("pbcoreInstantiation") && !instantiations.empty?
36
+ instantiations.collect { |i| new_doc.root.add_child(i.root.to_xml) }
37
+ end
19
38
  end
20
39
  return new_doc
21
40
  end
@@ -1,3 +1,3 @@
1
1
  module HydraPbcore
2
- VERSION = "2.2.0rc1"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -194,6 +194,23 @@ describe HydraPbcore::Datastream::Document do
194
194
  save_template @object_ds.to_pbcore_xml, "document_valid.xml"
195
195
  @object_ds.valid?.should == []
196
196
  end
197
+
198
+ describe "xml document with instantiations" do
199
+
200
+ before(:each) do
201
+ @digital = HydraPbcore::Datastream::Instantiation.new(nil, nil)
202
+ @digital.define :digital
203
+ @physical = HydraPbcore::Datastream::Instantiation.new(nil, nil)
204
+ @physical.define :physical
205
+ end
206
+
207
+ it "should validate against the PBCore schema" do
208
+ save_template @object_ds.to_pbcore_xml([@digital, @physical]), "document_with_instantiations_valid.xml"
209
+ HydraPbcore.is_valid?(Nokogiri::XML(sample("document_with_instantiations_valid.xml"))).should be_true
210
+ end
211
+
212
+ end
213
+
197
214
  end
198
215
 
199
216
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-pbcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0rc1
5
- prerelease: 5
4
+ version: 2.2.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Wead
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-26 00:00:00.000000000 Z
12
+ date: 2013-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active-fedora
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: solrizer
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - <
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - <
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: yard
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -202,16 +218,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
218
  version: '0'
203
219
  segments:
204
220
  - 0
205
- hash: 3789772575956433522
221
+ hash: 267528676452476624
206
222
  required_rubygems_version: !ruby/object:Gem::Requirement
207
223
  none: false
208
224
  requirements:
209
- - - ! '>'
225
+ - - ! '>='
210
226
  - !ruby/object:Gem::Version
211
- version: 1.3.1
227
+ version: '0'
228
+ segments:
229
+ - 0
230
+ hash: 267528676452476624
212
231
  requirements: []
213
232
  rubyforge_project:
214
- rubygems_version: 1.8.24
233
+ rubygems_version: 1.8.23
215
234
  signing_key:
216
235
  specification_version: 3
217
236
  summary: A Hydra gem that offers PBCore datastream definitions using OM