bolognese 0.4.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +326 -11
  5. data/lib/bolognese/author_utils.rb +7 -5
  6. data/lib/bolognese/cli.rb +20 -19
  7. data/lib/bolognese/crossref.rb +11 -49
  8. data/lib/bolognese/datacite.rb +16 -33
  9. data/lib/bolognese/datacite_utils.rb +28 -25
  10. data/lib/bolognese/doi_utils.rb +1 -1
  11. data/lib/bolognese/metadata.rb +55 -13
  12. data/lib/bolognese/schema_org.rb +12 -60
  13. data/lib/bolognese/utils.rb +24 -12
  14. data/lib/bolognese/version.rb +1 -1
  15. data/spec/cli_spec.rb +13 -0
  16. data/spec/crossref_spec.rb +6 -1
  17. data/spec/datacite_spec.rb +6 -1
  18. data/spec/fixtures/schema_org.json +44 -0
  19. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/default.yml +760 -0
  20. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/default.yml +214 -0
  21. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/default.yml +653 -0
  22. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/Schema_org_JSON.yml +719 -0
  23. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_id/doi.yml +930 -0
  24. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_id/url.yml +930 -0
  25. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/Schema_org_JSON.yml +173 -0
  26. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/crossref_doi_not_url.yml +2 -2
  27. data/spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting.yml +42 -21
  28. data/spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting_schema_org_JSON.yml +653 -0
  29. data/spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata_as_datacite_xml/with_data_citation.yml +653 -0
  30. data/spec/metadata_spec.rb +9 -12
  31. data/spec/schema_org_spec.rb +41 -3
  32. data/spec/utils_spec.rb +3 -3
  33. metadata +12 -2
@@ -1,41 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bolognese::Metadata, vcr: true do
4
+
5
+ subject { Bolognese::Metadata.new }
6
+
4
7
  context "find PID provider" do
5
8
  it "crossref" do
6
9
  id = "https://doi.org/10.1371/journal.pone.0000030"
7
- subject = Bolognese::Metadata.new(id: id)
8
- expect(subject.provider).to eq("crossref")
10
+ expect(subject.find_provider(id)).to eq("crossref")
9
11
  end
10
12
 
11
13
  it "crossref doi not url" do
12
14
  id = "10.1371/journal.pone.0000030"
13
- subject = Bolognese::Metadata.new(id: id)
14
- expect(subject.provider).to eq("crossref")
15
+ expect(subject.find_provider(id)).to eq("crossref")
15
16
  end
16
17
 
17
18
  it "datacite" do
18
19
  id = "https://doi.org/10.5438/4K3M-NYVG"
19
- subject = Bolognese::Metadata.new(id: id)
20
- expect(subject.provider).to eq("datacite")
20
+ expect(subject.find_provider(id)).to eq("datacite")
21
21
  end
22
22
 
23
23
  it "datacite doi http" do
24
24
  id = "http://doi.org/10.5438/4K3M-NYVG"
25
- subject = Bolognese::Metadata.new(id: id)
26
- expect(subject.provider).to eq("datacite")
25
+ expect(subject.find_provider(id)).to eq("datacite")
27
26
  end
28
27
 
29
28
  it "orcid" do
30
29
  id = "http://orcid.org/0000-0002-0159-2197"
31
- subject = Bolognese::Metadata.new(id: id)
32
- expect(subject.provider).to eq("orcid")
30
+ expect(subject.find_provider(id)).to eq("orcid")
33
31
  end
34
32
 
35
33
  it "schema_org" do
36
34
  id = "https://blog.datacite.org/eating-your-own-dog-food"
37
- subject = Bolognese::Metadata.new(id: id)
38
- expect(subject.provider).to eq("schema_org")
35
+ expect(subject.find_provider(id)).to eq("schema_org")
39
36
  end
40
37
  end
41
38
  end
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bolognese::SchemaOrg, vcr: true do
4
- context "get metadata" do
5
- let(:id) { "https://doi.org/10.5438/4K3M-NYVG" }
4
+ let(:id) { "https://blog.datacite.org/eating-your-own-dog-food" }
5
+ let(:fixture_path) { "spec/fixtures/" }
6
6
 
7
- subject { Bolognese::SchemaOrg.new(id: id) }
7
+ subject { Bolognese::SchemaOrg.new(id: id) }
8
8
 
9
+ context "get metadata" do
9
10
  it "BlogPosting" do
10
11
  expect(subject.id).to eq("https://doi.org/10.5438/4k3m-nyvg")
11
12
  expect(subject.url).to eq("https://blog.datacite.org/eating-your-own-dog-food")
@@ -23,6 +24,11 @@ describe Bolognese::SchemaOrg, vcr: true do
23
24
  expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"DataCite")
24
25
  end
25
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
+
26
32
  it "not found error" do
27
33
  id = "https://doi.org/10.5438/4K3M-NYVGx"
28
34
  subject = Bolognese::SchemaOrg.new(id: id)
@@ -30,4 +36,36 @@ describe Bolognese::SchemaOrg, vcr: true do
30
36
  expect(subject.exists?).to be false
31
37
  end
32
38
  end
39
+
40
+ context "get metadata as string" do
41
+ it "BlogPosting" do
42
+ string = File.read(fixture_path + 'schema_org.json')
43
+ subject = Bolognese::SchemaOrg.new(string: string)
44
+
45
+ expect(subject.id).to eq("https://doi.org/10.5438/4k3m-nyvg")
46
+ expect(subject.url).to eq("https://blog.datacite.org/eating-your-own-dog-food")
47
+ expect(subject.type).to eq("BlogPosting")
48
+ expect(subject.author).to eq([{"@type"=>"Person", "@id"=>"http://orcid.org/0000-0003-1419-2405", "givenName"=>"Martin", "familyName"=>"Fenner"}])
49
+ expect(subject.name).to eq("Eating your own Dog Food")
50
+ expect(subject.alternate_name).to eq("MS-49-3632-5083")
51
+ expect(subject.description).to start_with("Eating your own dog food")
52
+ expect(subject.keywords).to eq("datacite, doi, metadata, featured")
53
+ expect(subject.date_published).to eq("2016-12-20")
54
+ expect(subject.date_modified).to eq("2016-12-20")
55
+ expect(subject.is_part_of).to eq("@type"=>"Blog", "@id"=>"https://doi.org/10.5438/0000-00ss", "name"=>"DataCite Blog")
56
+ expect(subject.citation).to eq([{"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/0012"},
57
+ {"@type"=>"CreativeWork", "@id"=>"https://doi.org/10.5438/55e5-t5c0"}])
58
+ expect(subject.publisher).to eq("@type"=>"Organization", "name"=>"DataCite")
59
+ end
60
+ end
61
+
62
+ context "get metadata as datacite xml" do
63
+ it "with data citation" do
64
+ expect(subject.validation_errors).to be_empty
65
+ datacite = Maremma.from_xml(subject.as_datacite).fetch("resource", {})
66
+ expect(datacite.dig("titles", "title")).to eq("Eating your own Dog Food")
67
+ expect(datacite.dig("relatedIdentifiers", "relatedIdentifier").count).to eq(3)
68
+ expect(datacite.dig("relatedIdentifiers", "relatedIdentifier").first).to eq("relatedIdentifierType"=>"DOI", "relationType"=>"IsPartOf", "text"=>"https://doi.org/10.5438/0000-00ss")
69
+ end
70
+ end
33
71
  end
@@ -77,16 +77,16 @@ describe Bolognese::Crossref, vcr: true do
77
77
  end
78
78
  end
79
79
 
80
- context "normalize url" do
80
+ context "normalize id" do
81
81
  it "doi" do
82
82
  doi = "10.5061/DRYAD.8515"
83
- response = subject.normalize_url(doi)
83
+ response = subject.normalize_id(doi)
84
84
  expect(response).to eq("https://doi.org/10.5061/dryad.8515")
85
85
  end
86
86
 
87
87
  it "url" do
88
88
  url = "https://blog.datacite.org/eating-your-own-dog-food/"
89
- response = subject.normalize_url(url)
89
+ response = subject.normalize_id(url)
90
90
  expect(response).to eq("https://blog.datacite.org/eating-your-own-dog-food")
91
91
  end
92
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolognese
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-18 00:00:00.000000000 Z
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maremma
@@ -346,13 +346,17 @@ files:
346
346
  - spec/doi_utils_spec.rb
347
347
  - spec/fixtures/crossref.xml
348
348
  - spec/fixtures/datacite.xml
349
+ - spec/fixtures/schema_org.json
349
350
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_crossref.yml
350
351
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_datacite.yml
351
352
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_schema_org.yml
353
+ - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/default.yml
352
354
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/as_datacite.yml
353
355
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/as_schema_org.yml
356
+ - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/default.yml
354
357
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/as_datacite.yml
355
358
  - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/as_schema_org.yml
359
+ - spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/default.yml
356
360
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/crossref.yml
357
361
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/datacite.yml
358
362
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/medra.yml
@@ -360,6 +364,7 @@ files:
360
364
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/DOI_with_ORCID_ID.yml
361
365
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/DOI_with_SICI_DOI.yml
362
366
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/DOI_with_data_citation.yml
367
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/Schema_org_JSON.yml
363
368
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/date_in_future.yml
364
369
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/journal_article.yml
365
370
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/not_found_error.yml
@@ -379,6 +384,8 @@ files:
379
384
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/dx_doi_org_url.yml
380
385
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/https_url.yml
381
386
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/not_valid_doi_prefix.yml
387
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_id/doi.yml
388
+ - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_id/url.yml
382
389
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_ids/doi.yml
383
390
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_ids/url.yml
384
391
  - spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_url/doi.yml
@@ -397,6 +404,7 @@ files:
397
404
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/BlogPosting.yml
398
405
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/Dataset.yml
399
406
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/Date.yml
407
+ - spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/Schema_org_JSON.yml
400
408
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata_as_string/Dataset.yml
401
409
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_alternate_identifiers/insert.yml
402
410
  - spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_contributors/insert.yml
@@ -427,7 +435,9 @@ files:
427
435
  - spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/datacite_doi_http.yml
428
436
  - spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/orcid.yml
429
437
  - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting.yml
438
+ - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting_schema_org_JSON.yml
430
439
  - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/not_found_error.yml
440
+ - spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata_as_datacite_xml/with_data_citation.yml
431
441
  - spec/metadata_spec.rb
432
442
  - spec/orcid_spec.rb
433
443
  - spec/schema_org_spec.rb