solr_ead 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solr_ead/behaviors.rb +14 -10
- data/lib/solr_ead/component.rb +3 -2
- data/lib/solr_ead/version.rb +1 -1
- data/spec/component_spec.rb +27 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fdef7b50871ffde537ec7625ce858bf30a780bd
|
4
|
+
data.tar.gz: d54d41cc1719a04954100e77f789f97c02033107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e1344df2d9ba2880aa8f5fb1feeea3acb9cc36fbd6a3d00dda3866a55488757e333fe32b19cc9e8b07c718cc5980935f319836e48ddfa1ab28bb8e17d930113
|
7
|
+
data.tar.gz: 0121dea63780951b4395a9d4c4510aa025cd39414c417aed19b10b30411901d191a0eb2b96d0f6c40e414dedcbf0369e95d75e00077ff0c7c226e96681c5b753
|
data/lib/solr_ead/behaviors.rb
CHANGED
@@ -6,14 +6,18 @@ module SolrEad::Behaviors
|
|
6
6
|
|
7
7
|
# Takes a file as its input and returns a Nokogiri::XML::NodeSet of component <c> nodes
|
8
8
|
#
|
9
|
-
# It'll make an attempt at substituting numbered component levels for non-numbered
|
9
|
+
# It'll make an attempt at substituting numbered component levels (c01..c12) for non-numbered
|
10
10
|
# ones.
|
11
|
+
# @param [String] `file` pathname to file with EAD data
|
11
12
|
def components(file)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
doc = Nokogiri::XML(File.read(file))
|
14
|
+
doc.remove_namespaces!
|
15
|
+
(1..12).each do |i| # EAD spec provides 12 levels of components
|
16
|
+
doc.xpath("//c#{'%02d' % i}").each do |node|
|
17
|
+
node.name = 'c'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
doc.xpath('//c')
|
17
21
|
end
|
18
22
|
|
19
23
|
# Used in conjunction with #components, this takes a single Nokogiri::XML::Element
|
@@ -117,10 +121,10 @@ module SolrEad::Behaviors
|
|
117
121
|
end
|
118
122
|
end
|
119
123
|
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
+
# @param [Nokogiri::XML::Node] `node`
|
125
|
+
# @return true or false for a component with attached <c> child nodes.
|
126
|
+
def component_children?(node)
|
127
|
+
node.children.any? { |n| n.name == 'c' }
|
124
128
|
end
|
125
129
|
|
126
130
|
end
|
data/lib/solr_ead/component.rb
CHANGED
@@ -71,7 +71,8 @@ class SolrEad::Component
|
|
71
71
|
|
72
72
|
def to_solr(solr_doc = Hash.new)
|
73
73
|
super(solr_doc)
|
74
|
-
Solrizer.insert_field(solr_doc, "ref", self.ref.first.strip, :stored_sortable)
|
74
|
+
Solrizer.insert_field(solr_doc, "ref", self.ref.first.strip, :stored_sortable) unless self.ref.blank? || self.ref.first.blank?
|
75
|
+
solr_doc
|
75
76
|
end
|
76
77
|
|
77
|
-
end
|
78
|
+
end
|
data/lib/solr_ead/version.rb
CHANGED
data/spec/component_spec.rb
CHANGED
@@ -3,17 +3,18 @@ require "spec_helper"
|
|
3
3
|
describe SolrEad::Component do
|
4
4
|
|
5
5
|
context "with parent components" do
|
6
|
+
let(:xml_data) { fixture "component_template.xml" }
|
7
|
+
let(:additional_fields) { {
|
8
|
+
"id" => "TEST-0001ref010",
|
9
|
+
Solrizer.solr_name("ead", :stored_sortable) => "TEST-0001",
|
10
|
+
Solrizer.solr_name("parent", :stored_sortable) => "ref001",
|
11
|
+
Solrizer.solr_name("parent", :displayable) => ["ref001", "ref002", "ref003"],
|
12
|
+
Solrizer.solr_name("parent_unittitles", :displayable) => ["Series I", "Subseries A", "Subseries 1"],
|
13
|
+
Solrizer.solr_name("component_children", :type => :boolean) => false
|
14
|
+
} }
|
6
15
|
|
7
16
|
let(:subject) do
|
8
|
-
additional_fields
|
9
|
-
"id" => "TEST-0001ref010",
|
10
|
-
Solrizer.solr_name("ead", :stored_sortable) => "TEST-0001",
|
11
|
-
Solrizer.solr_name("parent", :stored_sortable) => "ref001",
|
12
|
-
Solrizer.solr_name("parent", :displayable) => ["ref001", "ref002", "ref003"],
|
13
|
-
Solrizer.solr_name("parent_unittitles", :displayable) => ["Series I", "Subseries A", "Subseries 1"],
|
14
|
-
Solrizer.solr_name("component_children", :type => :boolean) => FALSE
|
15
|
-
}
|
16
|
-
SolrEad::Component.from_xml(fixture "component_template.xml").to_solr(additional_fields)
|
17
|
+
SolrEad::Component.from_xml(xml_data).to_solr(additional_fields)
|
17
18
|
end
|
18
19
|
|
19
20
|
it "should accept additional fields from a hash" do
|
@@ -26,6 +27,21 @@ describe SolrEad::Component do
|
|
26
27
|
expect(subject[Solrizer.solr_name("ref", :stored_sortable)]).to eq("ref215")
|
27
28
|
end
|
28
29
|
|
30
|
+
context '#refs' do
|
31
|
+
context 'missing ones' do
|
32
|
+
let(:xml_data) { fixture("component_template.xml").read.gsub(/id=".*"\s/, '') }
|
33
|
+
it do
|
34
|
+
expect(subject[Solrizer.solr_name("ref", :stored_sortable)]).to be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'blank ones' do
|
38
|
+
let(:xml_data) { fixture("component_template.xml").read.gsub(/id=".*"\s/, 'id=" "') }
|
39
|
+
it do
|
40
|
+
expect(subject[Solrizer.solr_name("ref", :stored_sortable)]).to be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
29
45
|
end
|
30
46
|
|
31
47
|
context "without parent components" do
|
@@ -37,7 +53,7 @@ describe SolrEad::Component do
|
|
37
53
|
Solrizer.solr_name("parent", :stored_sortable) => "ref001",
|
38
54
|
Solrizer.solr_name("parent", :displayable) => ["ref001", "ref002", "ref003"],
|
39
55
|
Solrizer.solr_name("parent_unittitles", :displayable) => [],
|
40
|
-
Solrizer.solr_name("component_children", :type => :boolean) =>
|
56
|
+
Solrizer.solr_name("component_children", :type => :boolean) => false
|
41
57
|
}
|
42
58
|
SolrEad::Component.from_xml(fixture "component_template.xml").to_solr(additional_fields)
|
43
59
|
end
|
@@ -47,7 +63,7 @@ describe SolrEad::Component do
|
|
47
63
|
expect(subject[Solrizer.solr_name("accessrestrict", :displayable)].first).to match /^This item .* is available.$/
|
48
64
|
end
|
49
65
|
|
50
|
-
end
|
66
|
+
end
|
51
67
|
|
52
68
|
describe "formatting fields as html" do
|
53
69
|
let(:subject) { SolrEad::Component.from_xml(fixture "html_component.xml") }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solr_ead
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wead
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: om
|