solr_ead 0.7.4 → 0.7.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01f603d8f385b28bf4d15ddb66bce581ae869f85
4
- data.tar.gz: d277f1628997df455daed47a8182bce5d230dfbe
3
+ metadata.gz: 0fdef7b50871ffde537ec7625ce858bf30a780bd
4
+ data.tar.gz: d54d41cc1719a04954100e77f789f97c02033107
5
5
  SHA512:
6
- metadata.gz: eed1c50769951fec857c326d01decc890142e69ede412691894d82f56b0844166fc035dbd946c5276ac75375f94fecae2157e080dfec23a3091966c588045623
7
- data.tar.gz: ca8c4c060d1ba190b1949fe155ec7fb51c852b1b207c6bf4d54a1e3c72e1ff9d3e9b61dfb956dc47def656f77a2fef48be1cc32b076c8f63913236f1f9be7dca
6
+ metadata.gz: 4e1344df2d9ba2880aa8f5fb1feeea3acb9cc36fbd6a3d00dda3866a55488757e333fe32b19cc9e8b07c718cc5980935f319836e48ddfa1ab28bb8e17d930113
7
+ data.tar.gz: 0121dea63780951b4395a9d4c4510aa025cd39414c417aed19b10b30411901d191a0eb2b96d0f6c40e414dedcbf0369e95d75e00077ff0c7c226e96681c5b753
@@ -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
- raw = File.read(file)
13
- raw.gsub!(/xmlns="(.*?)"/, '')
14
- raw.gsub!(/c[0-9]{2,2}/,"c")
15
- xml = Nokogiri::XML(raw)
16
- return xml.xpath("//c")
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
- # Returns true or false for a component with attached <c> child nodes.
121
- def component_children?(node, t = Array.new)
122
- node.children.each { |n| t << n.name }
123
- t.include?("c") ? TRUE : FALSE
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SolrEad
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
@@ -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) => FALSE
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
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-04-20 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: om