eac 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac.rb +42 -12
- data/lib/eac/version.rb +1 -1
- data/spec/eac_spec.rb +25 -0
- 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: 743055a92de815917a402696dada62e5b3f662c4
|
4
|
+
data.tar.gz: 7a616c2a07a992bc42ba01b90b12eb91af07cd89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb03d9407a0f1bd613ae20a89d269d64573f11f26fc208af5015cb02541945942b6a77b8df05be02b53b1677cf128444e8f1f838e6b14b2289ae4a714d35982
|
7
|
+
data.tar.gz: 69e2f069345f61e508b5e9af301aa94faca0f4fbe388d00b3a00c06a56b00dca6faf9c837b8a94ff47f7bdaa6921575895ca9e2a27baa0bcff960ab53f2e6487
|
data/lib/eac.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
4
|
module EAC
|
5
|
-
|
5
|
+
|
6
6
|
class << self
|
7
7
|
def parse(content)
|
8
8
|
xml_doc = Nokogiri::XML(content)
|
9
|
-
entity_types = xml_doc.xpath("//ns:cpfDescription/ns:identity/ns:entityType",
|
9
|
+
entity_types = xml_doc.xpath("//ns:cpfDescription/ns:identity/ns:entityType",
|
10
10
|
ns:'urn:isbn:1-931666-33-4')
|
11
|
-
if entity_types.nil? || entity_types.length < 1
|
11
|
+
if entity_types.nil? || entity_types.length < 1
|
12
12
|
raise ArgumentError.new("entityType not found")
|
13
13
|
end
|
14
14
|
if entity_types.length > 1
|
@@ -26,7 +26,7 @@ module EAC
|
|
26
26
|
|
27
27
|
class Doc
|
28
28
|
def initialize(xml_doc)
|
29
|
-
@xml = xml_doc
|
29
|
+
@xml = xml_doc
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -41,19 +41,48 @@ module EAC
|
|
41
41
|
|
42
42
|
def names
|
43
43
|
if @names.nil?
|
44
|
-
|
44
|
+
@names = []
|
45
|
+
name_entries = @xml.xpath("//ns:cpfDescription/ns:identity/ns:nameEntry",
|
46
|
+
ns:'urn:isbn:1-931666-33-4')
|
47
|
+
name_entries.each do |entry|
|
48
|
+
@names << Name.new(entry)
|
49
|
+
end
|
45
50
|
end
|
46
51
|
@names
|
47
52
|
end
|
48
53
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
def occupations
|
55
|
+
if @occupations.nil?
|
56
|
+
@occupations = @xml.xpath("//ns:occupations/ns:occupation/ns:term",
|
57
|
+
ns:'urn:isbn:1-931666-33-4').map(&:text)
|
58
|
+
end
|
59
|
+
@occupations
|
60
|
+
end
|
61
|
+
|
62
|
+
def biography
|
63
|
+
if @biography.nil?
|
64
|
+
@biography = Biography.new(@xml)
|
65
|
+
end
|
66
|
+
@biography
|
67
|
+
end
|
68
|
+
|
69
|
+
class Biography
|
70
|
+
attr_reader :notes, :abstract
|
71
|
+
def initialize(xml)
|
72
|
+
@notes = xml.xpath('//ns:biogHist/ns:p', ns:'urn:isbn:1-931666-33-4').map(&:text)
|
73
|
+
|
74
|
+
xml_result = xml.xpath('//ns:biogHist/ns:abstract', ns:'urn:isbn:1-931666-33-4')
|
75
|
+
if xml_result.empty?
|
76
|
+
@abstract = ""
|
77
|
+
else
|
78
|
+
@abstract = xml_result.map(&:text).join('\n')
|
79
|
+
end
|
80
|
+
|
55
81
|
end
|
56
|
-
|
82
|
+
end
|
83
|
+
|
84
|
+
class Event
|
85
|
+
#item.xpath('ns:date', ns:'urn:isbn:1-931666-33-4')
|
57
86
|
end
|
58
87
|
|
59
88
|
class Name
|
@@ -83,6 +112,7 @@ module EAC
|
|
83
112
|
end
|
84
113
|
end
|
85
114
|
|
115
|
+
|
86
116
|
end
|
87
117
|
|
88
118
|
def EAC(*args, &block)
|
data/lib/eac/version.rb
CHANGED
data/spec/eac_spec.rb
CHANGED
@@ -31,10 +31,35 @@ describe EAC do
|
|
31
31
|
person
|
32
32
|
end
|
33
33
|
|
34
|
+
let (:cadell) { EAC(File.read("./data/yale_cadell.xml"))}
|
35
|
+
|
34
36
|
describe "attributes" do
|
35
37
|
it "should have 'record_id'" do
|
36
38
|
expect(person.record_id).to eq("RU007004")
|
37
39
|
end
|
40
|
+
|
41
|
+
it "should have occupations" do
|
42
|
+
expect(person.occupations).to eq(["Paleontologist", "Geologist", "Acting Secretary in Charge of the United States National Museum", "Secretary, Smithsonian Institution"])
|
43
|
+
end
|
44
|
+
it "should have biography data" do
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "biography" do
|
49
|
+
context "abstract" do
|
50
|
+
it "should be nil if no abstract present" do
|
51
|
+
expect(person.biography.abstract).to eq('')
|
52
|
+
end
|
53
|
+
it "should have text if abstract present" do
|
54
|
+
expect(cadell.biography.abstract).to include("Thomas Cadell was born in Bristol")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
context "notes" do
|
58
|
+
it "should have an array of strings with content from file" do
|
59
|
+
expect(person.biography.notes.length).to eq(7)
|
60
|
+
expect(person.biography.notes[1]).to include("Walcott was appointed Secretary of the Smithsonian")
|
61
|
+
end
|
62
|
+
end
|
38
63
|
end
|
39
64
|
|
40
65
|
describe "with name" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarah Allen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|