bolognese 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +2 -0
  4. data/lib/bolognese/cli.rb +5 -1
  5. data/lib/bolognese/crossref.rb +11 -6
  6. data/lib/bolognese/datacite.rb +10 -1
  7. data/lib/bolognese/datacite_utils.rb +36 -26
  8. data/lib/bolognese/schema_org.rb +13 -0
  9. data/lib/bolognese/utils.rb +8 -0
  10. data/lib/bolognese/version.rb +1 -1
  11. data/spec/cli_spec.rb +14 -0
  12. data/spec/crossref_spec.rb +11 -2
  13. data/spec/datacite_spec.rb +3 -0
  14. data/spec/datacite_utils_spec.rb +159 -0
  15. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/as_datacite.yml +653 -0
  16. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/as_schema_org.yml +653 -0
  17. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/with_ORCID_ID.yml +366 -0
  18. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/with_data_citation.yml +719 -0
  19. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/with_editor.yml +930 -0
  20. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/validate_url/DOI.yml +930 -0
  21. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/validate_url/URL.yml +930 -0
  22. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/validate_url/string.yml +930 -0
  23. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_alternate_identifiers/insert.yml +173 -0
  24. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_contributors/insert.yml +173 -0
  25. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_contributors/none.yml +173 -0
  26. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_creators/insert.yml +173 -0
  27. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_dates/insert.yml +173 -0
  28. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_descriptions/insert.yml +155 -0
  29. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_identifier/doi.yml +173 -0
  30. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator.yml +173 -0
  31. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_given_and_family_name.yml +173 -0
  32. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_only_name.yml +173 -0
  33. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_publication_year/insert.yml +173 -0
  34. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_publisher/insert.yml +173 -0
  35. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/get_related_identifier_type.yml +173 -0
  36. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/get_related_identifier_type_DOI.yml +173 -0
  37. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/get_related_identifier_type_URL.yml +173 -0
  38. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/insert.yml +173 -0
  39. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/rel_identifiers.yml +173 -0
  40. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_resource_type/insert.yml +173 -0
  41. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_rights_list/insert.yml +173 -0
  42. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_subjects/insert.yml +173 -0
  43. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_titles/doi.yml +173 -0
  44. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_titles/insert.yml +173 -0
  45. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_version/insert.yml +173 -0
  46. data/spec/schema_org_spec.rb +2 -0
  47. data/spec/utils_spec.rb +20 -0
  48. metadata +33 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf10f195bc1be468c9dddb8fa414f071b9389752
4
- data.tar.gz: 0adbaa0ec469a01e4f68c59c21dacc5e2d4440e9
3
+ metadata.gz: 6f368d772caba68f6a931b069036edd1fac3e15b
4
+ data.tar.gz: 85312771808c2971a7b10004f5b77cf6f6276952
5
5
  SHA512:
6
- metadata.gz: 0b29dc6ca64a5fd2f5c2cbfe4ac393a5eddbaac1334d0f6d07c9462a5471f81103855faa70f923d29de19fe184c50bbc19acc26863e0585c8549c4b7b694f6b1
7
- data.tar.gz: 8cf3694170ba6a2ecdb80ee3507bdafbcbaff9e05f5cd3e3ce439f29d42c07b5501298850e9f05f9bc9ce0ba09bc95368a20f784a20a55ad58a5e27324531a7c
6
+ metadata.gz: ed95b4b96238556e09a234defd26b402d72055204f31f4b9a0411774a5cca13079a91aeb80cccf3f812599a48b94c37fcffa1181ad324d730799894aafd37256
7
+ data.tar.gz: 2f33f803a3a5ef8b1e957db914225f55fc460a60f5706406f9b43ce3ec5a9542c99fd393267723aed7d5c400b2213f6fb48c334a23d8d8ab1044b1e158b712ca
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bolognese (0.4.2)
4
+ bolognese (0.4.3)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  builder (~> 3.2, >= 3.2.2)
7
7
  dotenv (~> 2.1, >= 2.1.1)
@@ -115,4 +115,4 @@ DEPENDENCIES
115
115
  webmock (~> 1.22, >= 1.22.3)
116
116
 
117
117
  BUNDLED WITH
118
- 1.14.4
118
+ 1.12.5
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/datacite/bolognese.svg?branch=master)](https://travis-ci.org/datacite/bolognese)
2
+
1
3
  # bolognese
2
4
 
3
5
  Command-line utility for conversion of DOI metadata from and to [schema.org](https://schema.org) in JSON-LD.
data/lib/bolognese/cli.rb CHANGED
@@ -30,8 +30,12 @@ module Bolognese
30
30
  puts Crossref.new(id: pid).as_schema_org
31
31
  when provider == "datacite" && options[:as] == "datacite"
32
32
  puts Datacite.new(id: pid).raw
33
- when "datacite"
33
+ when provider == "datacite"
34
34
  puts Datacite.new(id: pid).as_schema_org
35
+ when provider == "schema_org" && options[:as] == "datacite"
36
+ puts SchemaOrg.new(id: pid).as_datacite
37
+ when provider == "schema_org"
38
+ puts SchemaOrg.new(id: pid).as_schema_org
35
39
  else
36
40
  puts "not implemented"
37
41
  end
@@ -184,21 +184,25 @@ module Bolognese
184
184
  end
185
185
  end
186
186
 
187
+ def container_title
188
+ is_part_of.fetch("name", nil)
189
+ end
190
+
191
+ def has_part
192
+
193
+ end
194
+
187
195
  def citation
188
196
  citations = bibliographic_metadata.dig("citation_list", "citation")
189
- Array(citations).map do |c|
197
+ Array.wrap(citations).map do |c|
190
198
  { "@type" => "CreativeWork",
191
- "@id" => normalize_doi(c["doi"]),
199
+ "@id" => normalize_url(c["doi"]),
192
200
  "position" => c["key"],
193
201
  "name" => c["article_title"],
194
202
  "datePublished" => c["cYear"] }.compact
195
203
  end.presence
196
204
  end
197
205
 
198
- def related_identifiers
199
-
200
- end
201
-
202
206
  def provider
203
207
  { "@type" => "Organization",
204
208
  "name" => "Crossref" }
@@ -220,6 +224,7 @@ module Bolognese
220
224
  "pageStart" => page_start,
221
225
  "pageEnd" => page_end,
222
226
  "isPartOf" => is_part_of,
227
+ "hasPart" => has_part,
223
228
  "citation" => citation,
224
229
  "provider" => provider
225
230
  }.compact
@@ -88,6 +88,10 @@ module Bolognese
88
88
  get_authors(authors)
89
89
  end
90
90
 
91
+ def editor
92
+
93
+ end
94
+
91
95
  def version
92
96
  metadata.fetch("version", nil)
93
97
  end
@@ -134,7 +138,12 @@ module Bolognese
134
138
  end
135
139
 
136
140
  def publisher
137
- metadata.fetch("publisher")
141
+ { "@type" => "Organization",
142
+ "name" => metadata.fetch("publisher") }
143
+ end
144
+
145
+ def container_title
146
+ publisher.fetch("name", nil)
138
147
  end
139
148
 
140
149
  def provider
@@ -1,11 +1,5 @@
1
1
  module Bolognese
2
2
  module DataciteUtils
3
- # @resource_type = metadata.fetch("resource_type", nil)
4
- # @rights_list = metadata.fetch("rights_list", nil)
5
- # @descriptions = metadata.fetch("descriptions", nil)
6
- # @contributors = metadata.fetch("contributors", nil)
7
- # @alternate_identifier = metadata.fetch("alternate_identifier", nil)
8
- # @media = metadata.fetch("media", nil)
9
3
 
10
4
  SO_TO_DC_TRANSLATIONS = {
11
5
  "VideoObject" => "Audiovisual",
@@ -23,10 +17,10 @@ module Bolognese
23
17
  LICENSE_NAMES = {
24
18
  "http://creativecommons.org/publicdomain/zero/1.0/" => "Public Domain (CC0 1.0)",
25
19
  "http://creativecommons.org/licenses/by/3.0/" => "Creative Commons Attribution 3.0 (CC-BY 3.0)",
26
- "https://creativecommons.org/licenses/by/4.0/" => "Creative Commons Attribution 4.0 (CC-BY 4.0)",
27
- "https://creativecommons.org/licenses/by-nc/4.0/" => "Creative Commons Attribution Noncommercial 4.0 (CC-BY-NC 4.0)",
28
- "https://creativecommons.org/licenses/by-sa/4.0/" => "Creative Commons Attribution Share Alike 4.0 (CC-BY-SA 4.0)",
29
- "https://creativecommons.org/licenses/by-nc-nd/4.0/" => "Creative Commons Attribution Noncommercial No Derivaties 4.0 (CC-BY-NC-ND 4.0)"
20
+ "http://creativecommons.org/licenses/by/4.0/" => "Creative Commons Attribution 4.0 (CC-BY 4.0)",
21
+ "http://creativecommons.org/licenses/by-nc/4.0/" => "Creative Commons Attribution Noncommercial 4.0 (CC-BY-NC 4.0)",
22
+ "http://creativecommons.org/licenses/by-sa/4.0/" => "Creative Commons Attribution Share Alike 4.0 (CC-BY-SA 4.0)",
23
+ "http://creativecommons.org/licenses/by-nc-nd/4.0/" => "Creative Commons Attribution Noncommercial No Derivaties 4.0 (CC-BY-NC-ND 4.0)"
30
24
  }
31
25
 
32
26
  SCHEMA = File.expand_path("../../../resources/kernel-4.0/metadata.xsd", __FILE__)
@@ -76,7 +70,7 @@ module Bolognese
76
70
 
77
71
  def insert_creators(xml)
78
72
  xml.creators do
79
- Array(author).each do |creator|
73
+ Array.wrap(author).each do |creator|
80
74
  xml.creator do
81
75
  insert_person(xml, creator, "creator")
82
76
  end
@@ -88,7 +82,7 @@ module Bolognese
88
82
  return xml unless editor.present?
89
83
 
90
84
  xml.contributors do
91
- Array(editor).each do |contributor|
85
+ Array.wrap(editor).each do |contributor|
92
86
  xml.contributor("contributorType" => "Editor") do
93
87
  insert_person(xml, contributor, "contributor")
94
88
  end
@@ -97,12 +91,11 @@ module Bolognese
97
91
  end
98
92
 
99
93
  def insert_person(xml, person, type)
100
- person_name = [person["familyName"], person["givenName"]].compact.join(", ").presence || person["name"]
94
+ person_name = person["name"].presence || [person["familyName"], person["givenName"]].compact.join(", ")
101
95
 
102
- xml.send(:'creatorName', person_name) if type == "creator"
103
- xml.send(:'contributorName', person_name) if type == "contributor"
104
- xml.send(:'givenName', person["givenName"]) if person["givenName"].present?
105
- xml.send(:'familyName', person["familyName"]) if person["familyName"].present?
96
+ xml.send(type + "Name", person_name)
97
+ xml.givenName(person["givenName"]) if person["givenName"].present?
98
+ xml.familyName(person["familyName"]) if person["familyName"].present?
106
99
  xml.nameIdentifier(person["@id"], 'schemeURI' => 'http://orcid.org/', 'nameIdentifierScheme' => 'ORCID') if person["@id"].present?
107
100
  end
108
101
 
@@ -117,7 +110,7 @@ module Bolognese
117
110
  end
118
111
 
119
112
  def insert_publisher(xml)
120
- xml.publisher(is_part_of["name"])
113
+ xml.publisher(container_title)
121
114
  end
122
115
 
123
116
  def insert_publication_year(xml)
@@ -166,20 +159,37 @@ module Bolognese
166
159
  xml.version(version)
167
160
  end
168
161
 
169
- def is_part_of
170
- related_identifiers("IsPartOf").first
171
- end
162
+ def rel_identifiers
163
+ ipo = Array.wrap(is_part_of).map do |i|
164
+ {
165
+ "text" => i["@id"],
166
+ "related_identifier_type" => validate_url(i["@id"]),
167
+ "relation_type" => "IsPartOf" }
168
+ end.select { |i| i["related_identifier_type"].present? }
169
+
170
+ hp = Array.wrap(has_part).map do |i|
171
+ {
172
+ "text" => i["@id"],
173
+ "related_identifier_type" => validate_url(i["@id"]),
174
+ "relation_type" => "HasPart" }
175
+ end.select { |i| i["related_identifier_type"].present? }
176
+
177
+ c = Array.wrap(citation).map do |i|
178
+ {
179
+ "text" => i["@id"],
180
+ "related_identifier_type" => validate_url(i["@id"]),
181
+ "relation_type" => "References" }
182
+ end.select { |i| i["related_identifier_type"].present? }
172
183
 
173
- def related_identifiers
174
- Array.wrap(is_part_of) + Array(has_part) + Array(citation)
184
+ ipo + hp + c
175
185
  end
176
186
 
177
187
  def insert_related_identifiers(xml)
178
- return xml unless related_identifiers.present?
188
+ return xml unless rel_identifiers.present?
179
189
 
180
190
  xml.relatedIdentifiers do
181
- related_identifiers.each do |related_identifier|
182
- xml.relatedIdentifier(related_identifier[:value], 'relatedIdentifierType' => related_identifier[:related_identifier_type], 'relationType' => related_identifier[:relation_type])
191
+ rel_identifiers.each do |related_identifier|
192
+ xml.relatedIdentifier(related_identifier["text"], 'relatedIdentifierType' => related_identifier["related_identifier_type"], 'relationType' => related_identifier["relation_type"])
183
193
  end
184
194
  end
185
195
  end
@@ -79,6 +79,10 @@ module Bolognese
79
79
  Array(metadata.fetch("author", nil)).map { |a| a.except("name") }
80
80
  end
81
81
 
82
+ def editor
83
+ Array(metadata.fetch("editor", nil)).map { |a| a.except("name") }
84
+ end
85
+
82
86
  def description
83
87
  metadata.fetch("description", nil)
84
88
  end
@@ -127,6 +131,14 @@ module Bolognese
127
131
  metadata.fetch("publisher", nil)
128
132
  end
129
133
 
134
+ def container_title
135
+ if publisher.is_a?(Hash)
136
+ publisher.fetch("name", nil)
137
+ elsif publisher.is_a?(String)
138
+ publisher
139
+ end
140
+ end
141
+
130
142
  def provider
131
143
  metadata.fetch("provider", nil)
132
144
  end
@@ -139,6 +151,7 @@ module Bolognese
139
151
  "name" => name,
140
152
  "alternateName" => alternate_name,
141
153
  "author" => author,
154
+ "editor" => editor,
142
155
  "description" => description,
143
156
  "license" => license,
144
157
  "version" => version,
@@ -20,6 +20,14 @@ module Bolognese
20
20
  Array(/\A(?:http:\/\/orcid\.org\/)?(\d{4}-\d{4}-\d{4}-\d{3}[0-9X]+)\z/.match(orcid)).last
21
21
  end
22
22
 
23
+ def validate_url(str)
24
+ if /\A(?:(http|https):\/\/(dx\.)?doi.org\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(str)
25
+ "DOI"
26
+ elsif /\A(http|https):\/\//.match(str)
27
+ "URL"
28
+ end
29
+ end
30
+
23
31
  def parse_attributes(element)
24
32
  if element.is_a?(String)
25
33
  element
@@ -1,3 +1,3 @@
1
1
  module Bolognese
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -38,5 +38,19 @@ describe Bolognese::CLI do
38
38
  expect { subject.read id }.to output(/http:\/\/datacite.org\/schema\/kernel-3/).to_stdout
39
39
  end
40
40
  end
41
+
42
+ context "schema_org" do
43
+ let(:id) { "https://blog.datacite.org/eating-your-own-dog-food" }
44
+
45
+ it 'as schema_org' do
46
+ subject.options = { as: "schema_org" }
47
+ expect { subject.read id }.to output(/datacite, doi, metadata, featured/).to_stdout
48
+ end
49
+
50
+ it 'as datacite' do
51
+ subject.options = { as: "datacite" }
52
+ expect { subject.read id }.to output(/http:\/\/datacite.org\/schema\/kernel-4/).to_stdout
53
+ end
54
+ end
41
55
  end
42
56
  end
@@ -163,13 +163,14 @@ describe Bolognese::Crossref, vcr: true do
163
163
  end
164
164
 
165
165
  context "get metadata as datacite xml" do
166
- it "DOI with data citation" do
166
+ it "with data citation" do
167
167
  expect(subject.validation_errors).to be_empty
168
168
  datacite = Maremma.from_xml(subject.as_datacite).fetch("resource", {})
169
169
  expect(datacite.dig("titles", "title")).to eq("Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth")
170
+ expect(datacite.dig("relatedIdentifiers", "relatedIdentifier").count).to eq(25)
170
171
  end
171
172
 
172
- it "DOI with ORCID ID" do
173
+ it "with ORCID ID" do
173
174
  id = "https://doi.org/10.1155/2012/291294"
174
175
  subject = Bolognese::Crossref.new(id: id)
175
176
  expect(subject.validation_errors).to be_empty
@@ -177,5 +178,13 @@ describe Bolognese::Crossref, vcr: true do
177
178
  expect(datacite.dig("creators", "creator").count).to eq(7)
178
179
  expect(datacite.dig("creators", "creator").first).to eq("creatorName"=>"Thanassi, Wendy", "givenName"=>"Wendy", "familyName"=>"Thanassi")
179
180
  end
181
+
182
+ it "with editor" do
183
+ id = "https://doi.org/10.1371/journal.pone.0000030"
184
+ subject = Bolognese::Crossref.new(id: id)
185
+ expect(subject.validation_errors).to be_empty
186
+ datacite = Maremma.from_xml(subject.as_datacite).fetch("resource", {})
187
+ expect(datacite.dig("contributors", "contributor")).to eq("contributorType"=>"Editor", "contributorName"=>"Janbon, Guilhem", "givenName"=>"Guilhem", "familyName"=>"Janbon")
188
+ end
180
189
  end
181
190
  end
@@ -25,6 +25,7 @@ describe Bolognese::Datacite, vcr: true do
25
25
  expect(subject.has_part).to eq([{"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5061/dryad.8515/1"},
26
26
  {"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5061/dryad.8515/2"}])
27
27
  expect(subject.citation).to eq([{"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.1371/journal.ppat.1000446"}])
28
+ expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"Dryad Digital Repository")
28
29
  expect(subject.provider).to eq("@type"=>"Organization", "name"=>"DataCite")
29
30
  end
30
31
 
@@ -43,6 +44,7 @@ describe Bolognese::Datacite, vcr: true do
43
44
  expect(subject.is_part_of).to eq("@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/0000-00ss")
44
45
  expect(subject.citation).to eq([{"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/0012"},
45
46
  {"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/55e5-t5c0"}])
47
+ expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"DataCite")
46
48
  expect(subject.provider).to eq("@type"=>"Organization", "name"=>"DataCite")
47
49
  end
48
50
 
@@ -56,6 +58,7 @@ describe Bolognese::Datacite, vcr: true do
56
58
  expect(subject.name).to eq("The Minimum Size of Qubit Unextendible Product Bases")
57
59
  expect(subject.description).to start_with("We investigate the problem of constructing unextendible product bases in the qubit case")
58
60
  expect(subject.date_published).to eq("2013")
61
+ expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik GmbH, Wadern/Saarbruecken, Germany")
59
62
  expect(subject.provider).to eq("@type"=>"Organization", "name"=>"DataCite")
60
63
  end
61
64
  end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bolognese::Datacite, vcr: true do
4
+ let(:id) { "https://doi.org/10.5061/DRYAD.8515" }
5
+
6
+ subject { Bolognese::Datacite.new(id: id) }
7
+
8
+ context "insert_identifier" do
9
+ it "doi" do
10
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_identifier(xml) }.to_xml
11
+ response = Maremma.from_xml(xml)
12
+ expect(response["identifier"]).to eq("identifierType"=>"DOI", "text"=>"10.5061/DRYAD.8515")
13
+ end
14
+ end
15
+
16
+ context "insert_creators" do
17
+ it "insert" do
18
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_creators(xml) }.to_xml
19
+ response = Maremma.from_xml(xml)
20
+ expect(response.dig("creators", "creator").first).to eq("creatorName"=>"Ollomo, Benjamin", "givenName"=>"Benjamin", "familyName"=>"Ollomo")
21
+ end
22
+ end
23
+
24
+ context "insert_contributors" do
25
+ it "none" do
26
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_contributors(xml) }.to_xml
27
+ response = Maremma.from_xml(xml)
28
+ expect(response).to be_nil
29
+ end
30
+ end
31
+
32
+ context "insert_person" do
33
+ it "creator only name" do
34
+ person = { "name" => "Carberry, Josiah" }
35
+ type = "creator"
36
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_person(xml, person, type) }.to_xml
37
+ response = Maremma.from_xml(xml)
38
+ expect(response).to eq("creatorName"=>"Carberry, Josiah")
39
+ end
40
+
41
+ # it "creator given and family name" do
42
+ # person = { "givenName" => "Josiah", "familyName" => "Carberry" }
43
+ # type = "creator"
44
+ # xml = Nokogiri::XML::Builder.new { |xml| subject.insert_person(xml, person, type) }.to_xml
45
+ # response = Maremma.from_xml(xml)
46
+ # expect(response).to eq("creatorName"=>"Carberry, Josiah")
47
+ # end
48
+ end
49
+
50
+ context "insert_titles" do
51
+ it "insert" do
52
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_titles(xml) }.to_xml
53
+ response = Maremma.from_xml(xml)
54
+ expect(response.dig("titles", "title")).to eq("Data from: A new malaria agent in African hominids.")
55
+ end
56
+ end
57
+
58
+ context "insert_publisher" do
59
+ it "insert" do
60
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_publisher(xml) }.to_xml
61
+ response = Maremma.from_xml(xml)
62
+ expect(response["publisher"]).to eq("Dryad Digital Repository")
63
+ end
64
+ end
65
+
66
+ context "insert_publication_year" do
67
+ it "insert" do
68
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_publication_year(xml) }.to_xml
69
+ response = Maremma.from_xml(xml)
70
+ expect(response["publicationYear"]).to eq("2011")
71
+ end
72
+ end
73
+
74
+ context "insert_resource_type" do
75
+ it "insert" do
76
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_resource_type(xml) }.to_xml
77
+ response = Maremma.from_xml(xml)
78
+ expect(response["resourceType"]).to eq("resourceTypeGeneral"=>"Dataset", "text"=>"DataPackage")
79
+ end
80
+ end
81
+
82
+ context "insert_alternate_identifiers" do
83
+ it "insert" do
84
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_alternate_identifiers(xml) }.to_xml
85
+ response = Maremma.from_xml(xml)
86
+ expect(response.dig("alternateIdentifiers", "alternateIdentifier")).to eq("alternateIdentifierType"=>"Local accession number", "text"=>"Ollomo B, Durand P, Prugnolle F, Douzery EJP, Arnathau C, Nkoghe D, Leroy E, Renaud F (2009) A new malaria agent in African hominids. PLoS Pathogens 5(5): e1000446.")
87
+ end
88
+ end
89
+
90
+ context "insert_dates" do
91
+ it "insert" do
92
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_dates(xml) }.to_xml
93
+ response = Maremma.from_xml(xml)
94
+ expect(response.dig("dates", "date")).to eq("dateType"=>"Issued", "text"=>"2011")
95
+ end
96
+ end
97
+
98
+ context "insert_subjects" do
99
+ it "insert" do
100
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_subjects(xml) }.to_xml
101
+ response = Maremma.from_xml(xml)
102
+ expect(response.dig("subjects", "subject")).to eq(["Phylogeny", "Malaria", "Parasites", "Taxonomy", "Mitochondrial genome", "Africa", "Plasmodium"])
103
+ end
104
+ end
105
+
106
+ context "insert_version" do
107
+ it "insert" do
108
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_version(xml) }.to_xml
109
+ response = Maremma.from_xml(xml)
110
+ expect(response.fetch("version", nil)).to eq("1")
111
+ end
112
+ end
113
+
114
+ context "insert_related_identifiers" do
115
+ it "rel_identifiers" do
116
+ expect(subject.rel_identifiers).to eq([{"text"=>"https://doi.org/10.5061/dryad.8515/1",
117
+ "related_identifier_type"=>"DOI",
118
+ "relation_type"=>"HasPart"},
119
+ {"text"=>"https://doi.org/10.5061/dryad.8515/2",
120
+ "related_identifier_type"=>"DOI",
121
+ "relation_type"=>"HasPart"},
122
+ {"text"=>"https://doi.org/10.1371/journal.ppat.1000446",
123
+ "related_identifier_type"=>"DOI",
124
+ "relation_type"=>"References"}])
125
+ end
126
+
127
+ it "insert" do
128
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_related_identifiers(xml) }.to_xml
129
+ response = Maremma.from_xml(xml)
130
+ expect(response.dig("relatedIdentifiers", "relatedIdentifier")).to eq([{"relatedIdentifierType"=>"DOI",
131
+ "relationType"=>"HasPart",
132
+ "text"=>"https://doi.org/10.5061/dryad.8515/1"},
133
+ {"relatedIdentifierType"=>"DOI",
134
+ "relationType"=>"HasPart",
135
+ "text"=>"https://doi.org/10.5061/dryad.8515/2"},
136
+ {"relatedIdentifierType"=>"DOI",
137
+ "relationType"=>"References",
138
+ "text"=>"https://doi.org/10.1371/journal.ppat.1000446"}])
139
+ end
140
+ end
141
+
142
+ context "insert_rights_list" do
143
+ it "insert" do
144
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_rights_list(xml) }.to_xml
145
+ response = Maremma.from_xml(xml)
146
+ expect(response.dig("rightsList", "rights")).to eq("rightsURI"=>"http://creativecommons.org/publicdomain/zero/1.0/", "text"=>"Public Domain (CC0 1.0)")
147
+ end
148
+ end
149
+
150
+ context "insert_descriptions" do
151
+ it "insert" do
152
+ id = "https://doi.org/10.5438/4K3M-NYVG"
153
+ subject = Bolognese::Datacite.new(id: id)
154
+ xml = Nokogiri::XML::Builder.new { |xml| subject.insert_descriptions(xml) }.to_xml
155
+ response = Maremma.from_xml(xml)
156
+ expect(response.dig("descriptions", "description")).to eq("descriptionType" => "Abstract", "text" => "Eating your own dog food is a slang term to describe that an organization should itself use the products and services it provides. For DataCite this means that we should use DOIs with appropriate metadata and strategies for long-term preservation for...")
157
+ end
158
+ end
159
+ end