bolognese 0.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -30,6 +30,11 @@ describe Bolognese::Metadata, vcr: true do
30
30
  expect(subject.find_from_format(id: id)).to eq("orcid")
31
31
  end
32
32
 
33
+ it "github" do
34
+ id = "https://github.com/datacite/maremma"
35
+ expect(subject.find_from_format(id: id)).to eq("codemeta")
36
+ end
37
+
33
38
  it "schema_org" do
34
39
  id = "https://blog.datacite.org/eating-your-own-dog-food"
35
40
  expect(subject.find_from_format(id: id)).to eq("schema_org")
@@ -47,12 +52,17 @@ describe Bolognese::Metadata, vcr: true do
47
52
 
48
53
  it "crossref" do
49
54
  string = IO.read(fixture_path + "crossref.xml")
50
- expect(subject.find_from_format(string: string)).to eq("crossref")
55
+ expect(subject.find_from_format(string: string, ext: ".xml")).to eq("crossref")
51
56
  end
52
57
 
53
58
  it "datacite" do
54
59
  string = IO.read(fixture_path + "datacite.xml")
55
- expect(subject.find_from_format(string: string)).to eq("datacite")
60
+ expect(subject.find_from_format(string: string, ext: ".xml")).to eq("datacite")
61
+ end
62
+
63
+ it "codemeta" do
64
+ string = IO.read(fixture_path + "codemeta.json")
65
+ expect(subject.find_from_format(string: string, filename: "codemeta.json")).to eq("codemeta")
56
66
  end
57
67
  end
58
68
  end
@@ -65,7 +65,21 @@ describe Bolognese::SchemaOrg, vcr: true do
65
65
  datacite = Maremma.from_xml(subject.as_datacite).fetch("resource", {})
66
66
  expect(datacite.dig("titles", "title")).to eq("Eating your own Dog Food")
67
67
  expect(datacite.dig("relatedIdentifiers", "relatedIdentifier").count).to eq(3)
68
- expect(datacite.dig("relatedIdentifiers", "relatedIdentifier").first).to eq("relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf", "__content__"=>"https://doi.org/10.5438/0000-00ss")
68
+ expect(datacite.dig("relatedIdentifiers", "relatedIdentifier").first).to eq("relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf", "__content__"=>"https://doi.org/10.5438/0000-00ss")
69
+ end
70
+ end
71
+
72
+ context "get metadata as bibtex" do
73
+ it "with data citation" do
74
+ bibtex = BibTeX.parse(subject.as_bibtex).to_a(quotes: '').first
75
+ expect(bibtex[:bibtex_type].to_s).to eq("article")
76
+ expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.5438/4k3m-nyvg")
77
+ expect(bibtex[:doi]).to eq("10.5438/4k3m-nyvg")
78
+ expect(bibtex[:title]).to eq("Eating your own Dog Food")
79
+ expect(bibtex[:author]).to eq("Fenner, Martin")
80
+ expect(bibtex[:publisher]).to eq("DataCite")
81
+ expect(bibtex[:keywords]).to eq("datacite, doi, metadata, featured")
82
+ expect(bibtex[:year]).to eq("2016")
69
83
  end
70
84
  end
71
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolognese
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
@@ -318,7 +318,6 @@ files:
318
318
  - lib/bolognese/datacite_utils.rb
319
319
  - lib/bolognese/date_utils.rb
320
320
  - lib/bolognese/doi_utils.rb
321
- - lib/bolognese/github.rb
322
321
  - lib/bolognese/metadata.rb
323
322
  - lib/bolognese/orcid.rb
324
323
  - lib/bolognese/pubmed.rb
@@ -335,6 +334,7 @@ files:
335
334
  - resources/kernel-4.0/include/datacite-resourceType-v4.xsd
336
335
  - resources/kernel-4.0/include/datacite-titleType-v4.xsd
337
336
  - resources/kernel-4.0/metadata.xsd
337
+ - spec/author_utils_spec.rb
338
338
  - spec/bibtex_spec.rb
339
339
  - spec/cli_spec.rb
340
340
  - spec/codemeta_spec.rb
@@ -347,6 +347,7 @@ files:
347
347
  - spec/fixtures/crossref.xml
348
348
  - spec/fixtures/datacite.xml
349
349
  - spec/fixtures/datacite_missing_creator.xml
350
+ - spec/fixtures/maremma/codemeta.json
350
351
  - spec/fixtures/schema_org.json
351
352
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/convert_from_id/crossref/as_bibtex.yml
352
353
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/convert_from_id/crossref/as_crossref.yml
@@ -371,6 +372,17 @@ files:
371
372
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/convert_from_id/schema_org/to_bibtex.yml
372
373
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/convert_from_id/schema_org/to_datacite.yml
373
374
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/convert_from_id/schema_org/to_schema_org.yml
375
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/maremma.yml
376
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/maremma_schema_org_JSON.yml
377
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/no_codemeta_json.yml
378
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata/not_found_error.yml
379
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata_as_bibtex/maremma.yml
380
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata_as_datacite_xml/maremma.yml
381
+ - spec/fixtures/vcr_cassettes/Bolognese_Codemeta/get_metadata_as_schema_org_JSON/maremma.yml
382
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/author.yml
383
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/no_author.yml
384
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/single_author.yml
385
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/authors_as_string/with_organization.yml
374
386
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/crossref.yml
375
387
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/datacite.yml
376
388
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/medra.yml
@@ -437,6 +449,7 @@ files:
437
449
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_dates/insert.yml
438
450
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_descriptions/insert.yml
439
451
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_identifier/doi.yml
452
+ - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_given_and_family_name.yml
440
453
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_only_name.yml
441
454
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_publication_year/insert.yml
442
455
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_publisher/insert.yml
@@ -463,6 +476,7 @@ files:
463
476
  - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting.yml
464
477
  - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting_schema_org_JSON.yml
465
478
  - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/not_found_error.yml
479
+ - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata_as_bibtex/with_data_citation.yml
466
480
  - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata_as_datacite_xml/with_data_citation.yml
467
481
  - spec/metadata_spec.rb
468
482
  - spec/orcid_spec.rb
@@ -1,106 +0,0 @@
1
- module Bolognese
2
- class Github < Metadata
3
- # def get_github_metadata(url, options = {})
4
- # return {} if url.blank?
5
-
6
- # github_hash = github_from_url(url)
7
- # repo_url = "https://api.github.com/repos/#{github_hash[:owner]}/#{github_hash[:repo]}"
8
- # response = Maremma.get(repo_url, options.merge(bearer: ENV['GITHUB_PERSONAL_ACCESS_TOKEN']))
9
-
10
- # return { error: 'Resource not found.', status: 404 } if response.body.fetch("errors", nil).present?
11
-
12
- # author = get_github_owner(github_hash[:owner])
13
-
14
- # language = response.body.fetch("data", {}).fetch('language', nil)
15
- # type = language.present? && language != "HTML" ? 'computer_program' : 'webpage'
16
-
17
- # { "author" => [get_one_author(author)],
18
- # "title" => response.body.fetch("data", {}).fetch('description', nil).presence || github_hash[:repo],
19
- # "container-title" => "Github",
20
- # "issued" => response.body.fetch("data", {}).fetch('created_at', nil).presence || "0000",
21
- # "URL" => url,
22
- # "type" => type }
23
- # end
24
-
25
- # def get_github_owner_metadata(url, options = {})
26
- # return {} if url.blank?
27
-
28
- # github_hash = github_from_url(url)
29
- # owner_url = "https://api.github.com/users/#{github_hash[:owner]}"
30
- # response = Maremma.get(owner_url, options.merge(bearer: ENV['GITHUB_PERSONAL_ACCESS_TOKEN']))
31
-
32
- # return { error: 'Resource not found.', status: 404 } if response.body.fetch("data", {}).fetch("message", nil) == "Not Found"
33
-
34
- # author = response.body.fetch("data", {}).fetch('name', nil).presence || github_hash[:owner]
35
- # title = "Github profile for #{author}"
36
-
37
- # { "author" => [get_one_author(author)],
38
- # "title" => title,
39
- # "container-title" => "Github",
40
- # "issued" => response.body.fetch("data", {}).fetch('created_at', nil).presence || "0000",
41
- # "URL" => url,
42
- # "type" => 'entry' }
43
- # end
44
-
45
- # def get_github_release_metadata(url, options = {})
46
- # return {} if url.blank?
47
-
48
- # github_hash = github_from_url(url)
49
- # release_url = "https://api.github.com/repos/#{github_hash[:owner]}/#{github_hash[:repo]}/releases/tags/#{github_hash[:release]}"
50
- # response = Maremma.get(release_url, options.merge(bearer: ENV['GITHUB_PERSONAL_ACCESS_TOKEN']))
51
-
52
- # return { error: 'Resource not found.', status: 404 } if response.body.fetch("data", {})["message"] == "Not Found"
53
-
54
- # author = get_github_owner(github_hash[:owner])
55
-
56
- # { "author" => [get_one_author(author)],
57
- # "title" => response.body.fetch("data", {}).fetch('name', nil),
58
- # "container-title" => "Github",
59
- # "issued" => response.body.fetch("data", {}).fetch('created_at', nil).presence || "0000",
60
- # "URL" => url,
61
- # "type" => 'computer_program' }
62
- # end
63
-
64
- # def get_github_owner(owner)
65
- # url = "https://api.github.com/users/#{owner}"
66
- # response = Maremma.get(url, bearer: ENV['GITHUB_PERSONAL_ACCESS_TOKEN'])
67
-
68
- # return nil if response.body.fetch("data", {}).fetch("message", nil) == "Not Found"
69
-
70
- # response.body.fetch("data", {}).fetch('name', nil).presence || owner
71
- # end
72
-
73
- # def github_from_url(url)
74
- # return {} unless /\Ahttps:\/\/github\.com\/(.+)(?:\/)?(.+)?(?:\/tree\/)?(.*)\z/.match(url)
75
- # words = URI.parse(url).path[1..-1].split('/')
76
-
77
- # { owner: words[0],
78
- # repo: words[1],
79
- # release: words[3] }.compact
80
- # end
81
-
82
- # def github_repo_from_url(url)
83
- # github_from_url(url).fetch(:repo, nil)
84
- # end
85
-
86
- # def github_release_from_url(url)
87
- # github_from_url(url).fetch(:release, nil)
88
- # end
89
-
90
- # def github_owner_from_url(url)
91
- # github_from_url(url).fetch(:owner, nil)
92
- # end
93
-
94
- # def github_as_owner_url(github_hash)
95
- # "https://github.com/#{github_hash[:owner]}" if github_hash[:owner].present?
96
- # end
97
-
98
- # def github_as_repo_url(github_hash)
99
- # "https://github.com/#{github_hash[:owner]}/#{github_hash[:repo]}" if github_hash[:repo].present?
100
- # end
101
-
102
- # def github_as_release_url(github_hash)
103
- # "https://github.com/#{github_hash[:owner]}/#{github_hash[:repo]}/tree/#{github_hash[:release]}" if github_hash[:release].present?
104
- # end
105
- end
106
- end