bolognese 0.7 → 0.7.1

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +64 -0
  5. data/lib/bolognese/author_utils.rb +12 -0
  6. data/lib/bolognese/cli.rb +3 -2
  7. data/lib/bolognese/codemeta.rb +3 -3
  8. data/lib/bolognese/crossref.rb +4 -4
  9. data/lib/bolognese/datacite.rb +2 -2
  10. data/lib/bolognese/metadata.rb +1 -6
  11. data/lib/bolognese/schema_org.rb +4 -4
  12. data/lib/bolognese/utils.rb +52 -6
  13. data/lib/bolognese/version.rb +1 -1
  14. data/spec/author_utils_spec.rb +39 -0
  15. data/spec/cli_spec.rb +23 -0
  16. data/spec/codemeta_spec.rb +120 -40
  17. data/spec/fixtures/codemeta.json +0 -1
  18. data/spec/fixtures/maremma/codemeta.json +36 -0
  19. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/maremma.yml +97 -0
  20. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/maremma_schema_org_JSON.yml +97 -0
  21. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/no_codemeta_json.yml +66 -0
  22. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/not_found_error.yml +66 -0
  23. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata_as_bibtex/maremma.yml +97 -0
  24. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata_as_datacite_xml/maremma.yml +97 -0
  25. data/spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata_as_schema_org_JSON/maremma.yml +97 -0
  26. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/author.yml +930 -0
  27. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/no_author.yml +930 -0
  28. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/single_author.yml +930 -0
  29. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/with_organization.yml +930 -0
  30. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_given_and_family_name.yml +173 -0
  31. data/spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata_as_bibtex/with_data_citation.yml +653 -0
  32. data/spec/metadata_spec.rb +12 -2
  33. data/spec/schema_org_spec.rb +15 -1
  34. metadata +16 -2
  35. data/lib/bolognese/github.rb +0 -106
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 510d880a02cea7933abd7de597f9a4061dad981b
4
- data.tar.gz: 754fa0b49a23494efa1cac66c99688313bbaafca
3
+ metadata.gz: e529a85cd30e24af04203358d96f53dfe7c17526
4
+ data.tar.gz: 588daf5d103c64b25e4c06709dc6815c32f67587
5
5
  SHA512:
6
- metadata.gz: 9899dd154362fea725898b2895664704b1f6cdb7a981fd10225094b29273e467f45c45e545fd966ff06451df107c9625e906438172fac0fc44e55608e96165bb
7
- data.tar.gz: ba1af6c6cdc58219234ea03e7a989a8eb464fee854fe581ad280465d942db5212113a99e65c23d876e6642c3345d79ff5bdb7ec82c94bbc9a8709acb594eb803
6
+ metadata.gz: b0d7078349cd7b70cf40e996099c1017b9dbf9487580236aa8c8fa974ef28dc61ad7508ccf827c4ee9ea0a7fdd9c51ba9fa9e37554ecb807ab17a7bca8ee9673
7
+ data.tar.gz: 2772cbe1d11e52aa3835279161e826552dc3ddda889109d460d8a79996f94202784b689ce65172a9ee0af08c2e65f51d8dbd99a3e01a152f86231e400e65f9f4
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  *.gem
2
3
  *.rbc
3
4
  /.config
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bolognese (0.7)
4
+ bolognese (0.7.1)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  bibtex-ruby (~> 4.1)
7
7
  builder (~> 3.2, >= 3.2.2)
data/README.md CHANGED
@@ -868,6 +868,70 @@ bolognese https://blog.datacite.org/eating-your-own-dog-food -t bibtex
868
868
  }
869
869
  ```
870
870
 
871
+ Convert Codemeta to schema.org/JSON-LD:
872
+
873
+ ```
874
+ bolognese https://github.com/datacite/maremma
875
+
876
+ {
877
+ "@context":"http://schema.org",
878
+ "@type":"SoftwareSourceCode",
879
+ "@id":"https://doi.org/10.5438/qeg0-3gm3",
880
+ "url":"https://github.com/datacite/maremma",
881
+ "name":"Maremma: a Ruby library for simplified network calls",
882
+ "author":{
883
+ "@type":"person",
884
+ "@id":"http://orcid.org/0000-0003-0077-4738",
885
+ "name":"Martin Fenner"
886
+ },
887
+ "description":"Simplifies network calls, including json/xml parsing and error handling. Based on Faraday.",
888
+ "keywords":"faraday, excon, net/http",
889
+ "dateCreated":"2015-11-28",
890
+ "datePublished":"2017-02-24",
891
+ "dateModified":"2017-02-24",
892
+ "publisher":{
893
+ "@type":"Organization",
894
+ "name":"DataCite"
895
+ }
896
+ }
897
+ ```
898
+
899
+ Convert Codemeta to DataCite XML:
900
+
901
+ ```
902
+ bolognese https://github.com/datacite/maremma -t datacite
903
+
904
+ <?xml version="1.0" encoding="UTF-8"?>
905
+ <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
906
+ <identifier identifierType="DOI">10.5438/qeg0-3gm3</identifier>
907
+ <creators>
908
+ <creator>
909
+ <creatorName>Martin Fenner</creatorName>
910
+ <nameIdentifier schemeURI="http://orcid.org/" nameIdentifierScheme="ORCID">http://orcid.org/0000-0003-0077-4738</nameIdentifier>
911
+ </creator>
912
+ </creators>
913
+ <titles>
914
+ <title>Maremma: a Ruby library for simplified network calls</title>
915
+ </titles>
916
+ <publisher>DataCite</publisher>
917
+ <publicationYear>2017</publicationYear>
918
+ <resourceType resourceTypeGeneral="Software">SoftwareSourceCode</resourceType>
919
+ <subjects>
920
+ <subject>faraday</subject>
921
+ <subject>excon</subject>
922
+ <subject>net/http</subject>
923
+ </subjects>
924
+ <dates>
925
+ <date dateType="Created">2015-11-28</date>
926
+ <date dateType="Issued">2017-02-24</date>
927
+ <date dateType="Updated">2017-02-24</date>
928
+ </dates>
929
+ <descriptions>
930
+ <description descriptionType="Abstract">Simplifies network calls, including json/xml parsing and error handling. Based on Faraday.</description>
931
+ </descriptions>
932
+ </resource>
933
+ ```
934
+
871
935
  ## Development
872
936
 
873
937
  We use rspec for unit testing:
@@ -58,5 +58,17 @@ module Bolognese
58
58
 
59
59
  "http://orcid.org/" + name_identifier
60
60
  end
61
+
62
+ def authors_as_string(authors)
63
+ Array.wrap(authors).map do |a|
64
+ if a["@type"] == "organization"
65
+ "{" + a["name"] + "}"
66
+ elsif a["familyName"].present?
67
+ [a["familyName"], a["givenName"]].join(", ")
68
+ else
69
+ a["name"]
70
+ end
71
+ end.join(" and ").presence
72
+ end
61
73
  end
62
74
  end
data/lib/bolognese/cli.rb CHANGED
@@ -33,13 +33,14 @@ module Bolognese
33
33
  from = options[:from] || find_from_format(id: id)
34
34
  else
35
35
  ext = File.extname(input)
36
- if %w(.bib .xml).include? ext
36
+ filename = File.basename(input)
37
+ if %w(.bib .xml).include?(ext) || filename == "codemeta.json"
37
38
  string = IO.read(input)
38
39
  else
39
40
  $stderr.puts "File type #{ext} not supported"
40
41
  exit 1
41
42
  end
42
- from = options[:from] || find_from_format(string: string, ext: ext)
43
+ from = options[:from] || find_from_format(string: string, ext: ext, filename: filename)
43
44
  end
44
45
 
45
46
  to = options[:to] || "schema_org"
@@ -7,7 +7,7 @@ module Bolognese
7
7
  if string.present?
8
8
  @raw = string
9
9
  elsif id.present?
10
- response = Maremma.get(id, accept: "application/ld+json", raw: true)
10
+ response = Maremma.get(github_as_codemeta_url(id), raw: true)
11
11
  @raw = response.body.fetch("data", nil)
12
12
  end
13
13
  end
@@ -64,8 +64,8 @@ module Bolognese
64
64
  end
65
65
 
66
66
  def author
67
- a = Array.wrap(metadata.fetch("agents", nil)).map { |a| a.extract!("@type", "@id", "name") }
68
- array_unwrap(a)
67
+ arr = Array.wrap(metadata.fetch("agents", nil)).map { |a| a.slice("@type", "@id", "name") }
68
+ array_unwrap(arr)
69
69
  end
70
70
 
71
71
  def editor
@@ -172,23 +172,23 @@ module Bolognese
172
172
 
173
173
  def people(contributor_role)
174
174
  person = bibliographic_metadata.dig("contributors", "person_name")
175
- a = Array.wrap(person).select { |a| a["contributor_role"] == contributor_role }.map do |a|
175
+ arr = Array.wrap(person).select { |a| a["contributor_role"] == contributor_role }.map do |a|
176
176
  { "@type" => "Person",
177
177
  "@id" => parse_attributes(a["ORCID"]),
178
178
  "givenName" => a["given_name"],
179
179
  "familyName" => a["surname"] }.compact
180
180
  end
181
- array_unwrap(a)
181
+ array_unwrap(arr)
182
182
  end
183
183
 
184
184
  def funder
185
185
  fundref = Array.wrap(program_metadata).find { |a| a["name"] == "fundref" } || {}
186
- a = Array.wrap(fundref.fetch("assertion", [])).select { |a| a["name"] == "fundgroup" }.map do |f|
186
+ arr = Array.wrap(fundref.fetch("assertion", [])).select { |a| a["name"] == "fundgroup" }.map do |f|
187
187
  { "@type" => "Organization",
188
188
  "@id" => normalize_id(f.dig("assertion", "assertion", "__content__")),
189
189
  "name" => f.dig("assertion", "__content__").strip }.compact
190
190
  end
191
- array_unwrap(a)
191
+ array_unwrap(arr)
192
192
  end
193
193
 
194
194
  def date_published
@@ -187,13 +187,13 @@ module Bolognese
187
187
  end
188
188
 
189
189
  def related_identifiers(relation_type)
190
- a = Array.wrap(metadata.dig("relatedIdentifiers", "relatedIdentifier"))
190
+ arr = Array.wrap(metadata.dig("relatedIdentifiers", "relatedIdentifier"))
191
191
  .select { |r| relation_type.split(" ").include?(r["relationType"]) && %w(DOI URL).include?(r["relatedIdentifierType"]) }
192
192
  .map do |work|
193
193
  { "@type" => "CreativeWork",
194
194
  "@id" => normalize_id(work["__content__"]) }
195
195
  end
196
- array_unwrap(a)
196
+ array_unwrap(arr)
197
197
  end
198
198
 
199
199
  def same_as
@@ -28,11 +28,6 @@ module Bolognese
28
28
  [page_start, page_end].compact.join("-").presence
29
29
  end
30
30
 
31
- def author_string
32
- Array.wrap(author).map { |a| [a["familyName"], a["givenName"]].join(", ") }
33
- .join(" and ").presence
34
- end
35
-
36
31
  def publisher_string
37
32
  publisher.to_h.fetch("name", nil)
38
33
  end
@@ -96,7 +91,7 @@ module Bolognese
96
91
  bibtex_key: id,
97
92
  doi: doi,
98
93
  url: url,
99
- author: author_string,
94
+ author: authors_as_string(author),
100
95
  keywords: keywords,
101
96
  language: language,
102
97
  title: name,
@@ -62,13 +62,13 @@ module Bolognese
62
62
  end
63
63
 
64
64
  def author
65
- a = Array.wrap(metadata.fetch("author", nil)).map { |a| a.except("name") }
66
- array_unwrap(a)
65
+ arr = Array.wrap(metadata.fetch("author", nil)).map { |a| a.except("name") }
66
+ array_unwrap(arr)
67
67
  end
68
68
 
69
69
  def editor
70
- a = Array.wrap(metadata.fetch("editor", nil)).map { |a| a.except("name") }
71
- array_unwrap(a)
70
+ arr = Array.wrap(metadata.fetch("editor", nil)).map { |a| a.except("name") }
71
+ array_unwrap(arr)
72
72
  end
73
73
 
74
74
  def description
@@ -1,11 +1,11 @@
1
1
  module Bolognese
2
2
  module Utils
3
3
 
4
- def find_from_format(id: nil, string: nil, ext: nil)
4
+ def find_from_format(id: nil, string: nil, ext: nil, filename: nil)
5
5
  if id.present?
6
6
  find_from_format_by_id(id)
7
7
  elsif string.present?
8
- find_from_format_by_string(string, ext: ext)
8
+ find_from_format_by_string(string, ext: ext, filename: filename)
9
9
  end
10
10
  end
11
11
 
@@ -16,6 +16,8 @@ module Bolognese
16
16
  get_doi_ra(id).fetch("id", nil)
17
17
  elsif /\A(?:(http|https):\/\/orcid\.org\/)?(\d{4}-\d{4}-\d{4}-\d{3}[0-9X]+)\z/.match(id)
18
18
  "orcid"
19
+ elsif /\A(http|https):\/\/github\.com\/(.+)\z/.match(id)
20
+ "codemeta"
19
21
  else
20
22
  "schema_org"
21
23
  end
@@ -24,10 +26,12 @@ module Bolognese
24
26
  def find_from_format_by_string(string, options={})
25
27
  if options[:ext] == ".bib"
26
28
  "bibtex"
27
- elsif Maremma.from_xml(string).dig("doi_records", "doi_record", "crossref")
29
+ elsif options[:ext] == ".xml" && Maremma.from_xml(string).dig("doi_records", "doi_record", "crossref")
28
30
  "crossref"
29
- elsif Maremma.from_xml(string).dig("resource", "xmlns") == "http://datacite.org/schema/kernel-4"
31
+ elsif options[:ext] == ".xml" && Maremma.from_xml(string).dig("resource", "xmlns") == "http://datacite.org/schema/kernel-4"
30
32
  "datacite"
33
+ elsif options[:filename] == "codemeta.json"
34
+ "codemeta"
31
35
  end
32
36
  end
33
37
 
@@ -36,6 +40,7 @@ module Bolognese
36
40
  p = case from
37
41
  when "crossref" then Crossref.new(id: id, string: string)
38
42
  when "datacite" then Datacite.new(id: id, string: string, schema_version: options[:schema_version])
43
+ when "codemeta" then Codemeta.new(id: id, string: string)
39
44
  when "bibtex" then Bibtex.new(string: string)
40
45
  else SchemaOrg.new(id: id)
41
46
  end
@@ -104,8 +109,49 @@ module Bolognese
104
109
  end
105
110
 
106
111
  def normalize_ids(list)
107
- a = Array.wrap(list).map { |url| url.merge("@id" => normalize_id(url["@id"])) }
108
- array_unwrap(a)
112
+ arr = Array.wrap(list).map { |url| url.merge("@id" => normalize_id(url["@id"])) }
113
+ array_unwrap(arr)
114
+ end
115
+
116
+ def github_from_url(url)
117
+ return {} unless /\Ahttps:\/\/github\.com\/(.+)(?:\/)?(.+)?(?:\/tree\/)?(.*)\z/.match(url)
118
+ words = URI.parse(url).path[1..-1].split('/')
119
+
120
+ { owner: words[0],
121
+ repo: words[1],
122
+ release: words[3] }.compact
123
+ end
124
+
125
+ def github_repo_from_url(url)
126
+ github_from_url(url).fetch(:repo, nil)
127
+ end
128
+
129
+ def github_release_from_url(url)
130
+ github_from_url(url).fetch(:release, nil)
131
+ end
132
+
133
+ def github_owner_from_url(url)
134
+ github_from_url(url).fetch(:owner, nil)
135
+ end
136
+
137
+ def github_as_owner_url(url)
138
+ github_hash = github_from_url(url)
139
+ "https://github.com/#{github_hash[:owner]}" if github_hash[:owner].present?
140
+ end
141
+
142
+ def github_as_repo_url(url)
143
+ github_hash = github_from_url(url)
144
+ "https://github.com/#{github_hash[:owner]}/#{github_hash[:repo]}" if github_hash[:repo].present?
145
+ end
146
+
147
+ def github_as_release_url(url)
148
+ github_hash = github_from_url(url)
149
+ "https://github.com/#{github_hash[:owner]}/#{github_hash[:repo]}/tree/#{github_hash[:release]}" if github_hash[:release].present?
150
+ end
151
+
152
+ def github_as_codemeta_url(url)
153
+ github_hash = github_from_url(url)
154
+ "https://raw.githubusercontent.com/#{github_hash[:owner]}/#{github_hash[:repo]}/master/codemeta.json" if github_hash[:owner].present?
109
155
  end
110
156
  end
111
157
  end
@@ -1,3 +1,3 @@
1
1
  module Bolognese
2
- VERSION = "0.7"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bolognese::Crossref, vcr: true do
4
+ let(:id) { "https://doi.org/10.1371/journal.pone.0000030" }
5
+
6
+ subject { Bolognese::Crossref.new(id: id) }
7
+
8
+ context "authors_as_string" do
9
+ let(:author_with_organization) { [{"@type"=>"person",
10
+ "@id"=>"http://orcid.org/0000-0003-0077-4738",
11
+ "name"=>"Matt Jones"},
12
+ {"@type"=>"person",
13
+ "@id"=>"http://orcid.org/0000-0002-2192-403X",
14
+ "name"=>"Peter Slaughter"},
15
+ {"@type"=>"organization",
16
+ "@id"=>"http://orcid.org/0000-0002-3957-2474",
17
+ "name"=>"University of California, Santa Barbara"}] }
18
+
19
+ it "author" do
20
+ response = subject.authors_as_string(subject.author)
21
+ expect(response).to eq("Ralser, Markus and Heeren, Gino and Breitenbach, Michael and Lehrach, Hans and Krobitsch, Sylvia")
22
+ end
23
+
24
+ it "single author" do
25
+ response = subject.authors_as_string(subject.author.first)
26
+ expect(response).to eq("Ralser, Markus")
27
+ end
28
+
29
+ it "no author" do
30
+ response = subject.authors_as_string(nil)
31
+ expect(response).to be_nil
32
+ end
33
+
34
+ it "with organization" do
35
+ response = subject.authors_as_string(author_with_organization)
36
+ expect(response).to eq("Matt Jones and Peter Slaughter and {University of California, Santa Barbara}")
37
+ end
38
+ end
39
+ end
data/spec/cli_spec.rb CHANGED
@@ -158,6 +158,29 @@ describe Bolognese::CLI do
158
158
  end
159
159
  end
160
160
 
161
+ context "codemeta" do
162
+ let(:file) { fixture_path + "codemeta.json" }
163
+
164
+ it 'default' do
165
+ expect { subject.convert file }.to output(/datePublished/).to_stdout
166
+ end
167
+
168
+ it 'to schema_org' do
169
+ subject.options = { to: "schema_org" }
170
+ expect { subject.convert file }.to output(/datePublished/).to_stdout
171
+ end
172
+
173
+ it 'to datacite' do
174
+ subject.options = { to: "datacite" }
175
+ expect { subject.convert file }.to output(/http:\/\/datacite.org\/schema\/kernel-4/).to_stdout
176
+ end
177
+
178
+ it 'to bibtex' do
179
+ subject.options = { to: "bibtex" }
180
+ expect { subject.convert file }.to output(/@misc{https:\/\/doi.org\/10.5063\/f1m61h5x/).to_stdout
181
+ end
182
+ end
183
+
161
184
  # context "unsupported format" do
162
185
  # let(:file) { fixture_path + "crossref.xxx" }
163
186
  #
@@ -1,48 +1,54 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bolognese::Codemeta, vcr: true do
4
- # let(:id) { "https://blog.datacite.org/eating-your-own-dog-food" }
5
4
  let(:fixture_path) { "spec/fixtures/" }
6
- #
7
- # subject { Bolognese::SchemaOrg.new(id: id) }
5
+ let(:id) { "https://github.com/datacite/maremma" }
8
6
 
9
- # context "get metadata" do
10
- # it "BlogPosting" do
11
- # expect(subject.id).to eq("https://doi.org/10.5438/4k3m-nyvg")
12
- # expect(subject.url).to eq("https://blog.datacite.org/eating-your-own-dog-food")
13
- # expect(subject.type).to eq("BlogPosting")
14
- # expect(subject.author).to eq([{"@type"=>"Person", "@id"=>"http://orcid.org/0000-0003-1419-2405", "givenName"=>"Martin", "familyName"=>"Fenner"}])
15
- # expect(subject.name).to eq("Eating your own Dog Food")
16
- # expect(subject.alternate_name).to eq("MS-49-3632-5083")
17
- # expect(subject.description).to start_with("Eating your own dog food")
18
- # expect(subject.keywords).to eq("datacite, doi, metadata, featured")
19
- # expect(subject.date_published).to eq("2016-12-20")
20
- # expect(subject.date_modified).to eq("2016-12-20")
21
- # expect(subject.is_part_of).to eq("@type"=>"Blog", "@id"=>"https://doi.org/10.5438/0000-00ss", "name"=>"DataCite Blog")
22
- # expect(subject.citation).to eq([{"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/0012"},
23
- # {"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/55e5-t5c0"}])
24
- # expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"DataCite")
25
- # end
26
- #
27
- # it "BlogPosting schema.org JSON" do
28
- # json = JSON.parse(subject.as_schema_org)
29
- # expect(json["@id"]).to eq("https://doi.org/10.5438/4k3m-nyvg")
30
- # end
31
- #
32
- # it "not found error" do
33
- # id = "https://doi.org/10.5438/4K3M-NYVGx"
34
- # subject = Bolognese::SchemaOrg.new(id: id)
35
- # expect(subject.id).to be_nil
36
- # expect(subject.exists?).to be false
37
- # end
38
- # end
7
+ subject { Bolognese::Codemeta.new(id: id) }
8
+
9
+ context "get metadata" do
10
+ it "maremma" do
11
+ expect(subject.id).to eq("https://doi.org/10.5438/qeg0-3gm3")
12
+ expect(subject.url).to eq("https://github.com/datacite/maremma")
13
+ expect(subject.type).to eq("SoftwareSourceCode")
14
+ expect(subject.author).to eq("@id"=>"http://orcid.org/0000-0003-0077-4738", "@type"=>"person", "name"=>"Martin Fenner")
15
+ expect(subject.name).to eq("Maremma: a Ruby library for simplified network calls")
16
+ expect(subject.description).to start_with("Simplifies network calls")
17
+ expect(subject.keywords).to eq("faraday, excon, net/http")
18
+ expect(subject.date_created).to eq("2015-11-28")
19
+ expect(subject.date_published).to eq("2017-02-24")
20
+ expect(subject.date_modified).to eq("2017-02-24")
21
+ expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"DataCite")
22
+ end
23
+
24
+ it "maremma schema.org JSON" do
25
+ json = JSON.parse(subject.as_schema_org)
26
+ expect(json["@id"]).to eq("https://doi.org/10.5438/qeg0-3gm3")
27
+ expect(json["name"]).to eq("Maremma: a Ruby library for simplified network calls")
28
+ expect(json["author"]).to eq("@type"=>"person", "@id"=>"http://orcid.org/0000-0003-0077-4738", "name"=>"Martin Fenner")
29
+ end
30
+
31
+ it "no codemeta.json" do
32
+ id = "https://github.com/datacite/homepage"
33
+ subject = Bolognese::Codemeta.new(id: id)
34
+ expect(subject.id).to be_nil
35
+ expect(subject.exists?).to be false
36
+ end
37
+
38
+ it "not found error" do
39
+ id = "https://github.com/datacite/x"
40
+ subject = Bolognese::Codemeta.new(id: id)
41
+ expect(subject.id).to be_nil
42
+ expect(subject.exists?).to be false
43
+ end
44
+ end
39
45
 
40
46
  context "get metadata as string" do
41
47
  let(:string) { IO.read(fixture_path + 'codemeta.json') }
42
48
 
43
49
  subject { Bolognese::Codemeta.new(string: string) }
44
50
 
45
- it "SoftwareSourceCode" do
51
+ it "rdataone" do
46
52
  expect(subject.id).to eq("https://doi.org/10.5063/f1m61h5x")
47
53
  expect(subject.url).to eq("https://github.com/DataONEorg/rdataone")
48
54
  expect(subject.type).to eq("SoftwareSourceCode")
@@ -53,7 +59,6 @@ describe Bolognese::Codemeta, vcr: true do
53
59
  "@id"=>"http://orcid.org/0000-0002-2192-403X",
54
60
  "name"=>"Peter Slaughter"},
55
61
  {"@type"=>"organization",
56
- "@id"=>"http://orcid.org/0000-0002-3957-2474",
57
62
  "name"=>"University of California, Santa Barbara"}])
58
63
  expect(subject.name).to eq("R Interface to the DataONE REST API")
59
64
  expect(subject.description).to start_with("Provides read and write access to data and metadata")
@@ -64,18 +69,93 @@ describe Bolognese::Codemeta, vcr: true do
64
69
  expect(subject.date_modified).to eq("2016-05-27")
65
70
  expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"https://cran.r-project.org")
66
71
  end
72
+
73
+ it "maremma" do
74
+ string = IO.read(fixture_path + 'maremma/codemeta.json')
75
+ subject = Bolognese::Codemeta.new(string: string)
76
+ expect(subject.id).to eq("https://doi.org/10.5438/qeg0-3gm3")
77
+ expect(subject.url).to eq("https://github.com/datacite/maremma")
78
+ expect(subject.type).to eq("SoftwareSourceCode")
79
+ expect(subject.author).to eq("@id"=>"http://orcid.org/0000-0003-0077-4738", "@type"=>"person", "name"=>"Martin Fenner")
80
+ expect(subject.name).to eq("Maremma: a Ruby library for simplified network calls")
81
+ expect(subject.description).to start_with("Simplifies network calls")
82
+ expect(subject.keywords).to eq("faraday, excon, net/http")
83
+ expect(subject.date_created).to eq("2015-11-28")
84
+ expect(subject.date_published).to eq("2017-02-24")
85
+ expect(subject.date_modified).to eq("2017-02-24")
86
+ expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"DataCite")
87
+ end
67
88
  end
68
89
 
69
90
  context "get metadata as datacite xml" do
70
- let(:string) { IO.read(fixture_path + 'codemeta.json') }
71
-
72
- subject { Bolognese::Codemeta.new(string: string) }
73
-
74
- it "SoftwareSourceCode" do
91
+ it "rdataone" do
92
+ string = IO.read(fixture_path + 'codemeta.json')
93
+ subject = Bolognese::Codemeta.new(string: string)
75
94
  expect(subject.validation_errors).to be_empty
76
95
  datacite = Maremma.from_xml(subject.as_datacite).fetch("resource", {})
77
96
  expect(datacite.dig("titles", "title")).to eq("R Interface to the DataONE REST API")
97
+ expect(datacite.dig("creators", "creator")).to eq([{"creatorName"=>"Matt Jones",
98
+ "nameIdentifier"=>
99
+ {"schemeURI"=>"http://orcid.org/",
100
+ "nameIdentifierScheme"=>"ORCID",
101
+ "__content__"=>"http://orcid.org/0000-0003-0077-4738"}},
102
+ {"creatorName"=>"Peter Slaughter",
103
+ "nameIdentifier"=>
104
+ {"schemeURI"=>"http://orcid.org/",
105
+ "nameIdentifierScheme"=>"ORCID",
106
+ "__content__"=>"http://orcid.org/0000-0002-2192-403X"}},
107
+ {"creatorName"=>"University of California, Santa Barbara"}])
78
108
  expect(datacite.fetch("version")).to eq("2.0.0")
79
109
  end
110
+
111
+ it "maremma" do
112
+ expect(subject.validation_errors).to be_empty
113
+ datacite = Maremma.from_xml(subject.as_datacite).fetch("resource", {})
114
+ expect(datacite.dig("titles", "title")).to eq("Maremma: a Ruby library for simplified network calls")
115
+ expect(datacite.dig("creators", "creator")).to eq("creatorName"=>"Martin Fenner", "nameIdentifier"=>{"schemeURI"=>"http://orcid.org/", "nameIdentifierScheme"=>"ORCID", "__content__"=>"http://orcid.org/0000-0003-0077-4738"})
116
+ end
117
+ end
118
+
119
+ context "get metadata as schema.org JSON" do
120
+ it "rdataone" do
121
+ string = IO.read(fixture_path + 'codemeta.json')
122
+ subject = Bolognese::Codemeta.new(string: string)
123
+ json = JSON.parse(subject.as_schema_org)
124
+ expect(json["@id"]).to eq("https://doi.org/10.5063/f1m61h5x")
125
+ expect(json["@type"]).to eq("SoftwareSourceCode")
126
+ expect(json["name"]).to eq("R Interface to the DataONE REST API")
127
+ expect(json["author"]).to eq([{"@type"=>"person",
128
+ "@id"=>"http://orcid.org/0000-0003-0077-4738",
129
+ "name"=>"Matt Jones"},
130
+ {"@type"=>"person",
131
+ "@id"=>"http://orcid.org/0000-0002-2192-403X",
132
+ "name"=>"Peter Slaughter"},
133
+ {"@type"=>"organization",
134
+ "name"=>"University of California, Santa Barbara"}])
135
+ expect(json["version"]).to eq("2.0.0")
136
+ end
137
+
138
+ it "maremma" do
139
+ json = JSON.parse(subject.as_schema_org)
140
+ expect(json["@id"]).to eq("https://doi.org/10.5438/qeg0-3gm3")
141
+ expect(json["@type"]).to eq("SoftwareSourceCode")
142
+ expect(json["name"]).to eq("Maremma: a Ruby library for simplified network calls")
143
+ expect(json["author"]).to eq("@type"=>"person", "@id"=>"http://orcid.org/0000-0003-0077-4738", "name"=>"Martin Fenner")
144
+ end
145
+ end
146
+
147
+ context "get metadata as bibtex" do
148
+ it "maremma" do
149
+ bibtex = BibTeX.parse(subject.as_bibtex).to_a(quotes: '').first
150
+ expect(bibtex[:bibtex_type].to_s).to eq("misc")
151
+ expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.5438/qeg0-3gm3")
152
+ expect(bibtex[:doi]).to eq("10.5438/qeg0-3gm3")
153
+ expect(bibtex[:url]).to eq("https://github.com/datacite/maremma")
154
+ expect(bibtex[:title]).to eq("Maremma: a Ruby library for simplified network calls")
155
+ expect(bibtex[:author]).to eq("Fenner, Martin")
156
+ expect(bibtex[:publisher]).to eq("DataCite")
157
+ expect(bibtex[:keywords]).to eq("faraday, excon, net/http")
158
+ expect(bibtex[:year]).to eq("2017")
159
+ end
80
160
  end
81
161
  end