cirneco 0.5.7 → 0.5.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5848ad65bed8f39dfc0ca2cc41710494bb5951dd
4
- data.tar.gz: bed67d95cb6a626863e75ba84cfd81ca6045fe3c
3
+ metadata.gz: bc53bd40a384ab3df63764308d8f6267f230975a
4
+ data.tar.gz: 8596911b41e4513f9c947c0cb0b2a345d57e2a8d
5
5
  SHA512:
6
- metadata.gz: 30c52cd275ddea765d18c5ccc73ed4c14e9a5641fda8927e2af137023cf6a0af77e9291f5fb55f2c54fcf4ad2f47ea788b90c365eabce6fd55e631711f096fe5
7
- data.tar.gz: 97e24c85ada43a7b00ede4a60db77b90a1a6d65a6514148ffbf0bd477d90835a690a76d1ddde5a518123be4ce495a138c49eaffd4d386d31245b7d06c0c7eeb0
6
+ metadata.gz: 508aeb634c7e6b5af2cb88ee30e6f9b031ca85456f02b237c497050b5ac34f608c04a0f694b9507c577f0859b802fe012f36e8939fd3037c7aee3c22e739b43b
7
+ data.tar.gz: bfccc96e67b81775f5747bf00d89d71537d4d1c3d4e73c27401ecb2bd48d330a0de047c03a0ce5b85d92a8d7f8058416ea707b6d7382da6548532d99ef9b0cd5
data/.gitignore CHANGED
@@ -49,6 +49,9 @@ build-iPhoneSimulator/
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
51
 
52
+ # outputs
53
+ *.xml
54
+
52
55
  coverage/
53
56
  spec/fixtures/doi.yml
54
57
  .env
data/.travis.yml CHANGED
@@ -3,9 +3,12 @@ rvm:
3
3
  - 2.3.1
4
4
 
5
5
  before_install:
6
- - sudo add-apt-repository ppa:kalakris/cmake -y
7
- - sudo apt-get update -q
8
- - sudo apt-get install cmake -y
6
+ - wget https://github.com/jgm/pandoc/releases/download/1.15.2/pandoc-1.15.2-1-amd64.deb
7
+ - sudo dpkg -i pandoc-1.15.2-1-amd64.deb
8
+ - rm pandoc-1.15.2-1-amd64.deb
9
+ - sudo add-apt-repository ppa:kalakris/cmake -y
10
+ - sudo apt-get update -q
11
+ - sudo apt-get install cmake -y
9
12
 
10
13
  install:
11
14
  - travis_retry bundle install
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cirneco (0.5.7)
4
+ cirneco (0.5.8)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  base32-crockford-checksum (~> 0.2.2)
7
- bergamasco (~> 0.1.1)
7
+ bergamasco (~> 0.2)
8
8
  builder (~> 3.2, >= 3.2.2)
9
9
  dotenv (~> 2.1, >= 2.1.1)
10
10
  maremma (~> 3.1)
@@ -20,11 +20,11 @@ GEM
20
20
  minitest (~> 5.1)
21
21
  thread_safe (~> 0.3, >= 0.3.4)
22
22
  tzinfo (~> 1.1)
23
- addressable (2.5.0)
24
- public_suffix (~> 2.0, >= 2.0.2)
23
+ addressable (2.3.8)
25
24
  base32-crockford-checksum (0.2.3)
26
- bergamasco (0.1.4)
25
+ bergamasco (0.2.3)
27
26
  activesupport (~> 4.2, >= 4.2.5)
27
+ addressable (~> 2.3.8)
28
28
  builder (~> 3.2, >= 3.2.2)
29
29
  commonmarker (~> 0.14.0)
30
30
  loofah (~> 2.0, >= 2.0.3)
@@ -73,7 +73,6 @@ GEM
73
73
  mini_portile2 (~> 2.1.0)
74
74
  oj (2.13.1)
75
75
  pandoc-ruby (2.0.1)
76
- public_suffix (2.0.4)
77
76
  rack (2.0.1)
78
77
  rack-test (0.6.3)
79
78
  rack (>= 1.0)
data/cirneco.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  # Declary dependencies here, rather than in the Gemfile
18
18
  s.add_dependency 'maremma', '~> 3.1'
19
- s.add_dependency 'bergamasco', '~> 0.1.1'
19
+ s.add_dependency 'bergamasco', '~> 0.2'
20
20
  s.add_dependency 'base32-crockford-checksum', '~> 0.2.2'
21
21
  s.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
22
22
  s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
data/lib/cirneco/utils.rb CHANGED
@@ -57,8 +57,6 @@ module Cirneco
57
57
  "DOI removed from #{filename}"
58
58
  elsif updated_file != file
59
59
  "DOI #{doi} added to #{filename}"
60
- else
61
- "DOI #{doi} found in #{filename}"
62
60
  end
63
61
  end
64
62
 
@@ -68,26 +66,78 @@ module Cirneco
68
66
  end.join("\n")
69
67
  end
70
68
 
71
- def create_work_from_yaml(metadata:, **options)
72
- return "Error" unless ["doi", "author", "title", "date", "summary"].all? { |k| metadata.key? k }
69
+ def generate_metadata_for_work(filepath, options={})
70
+ metadata = Bergamasco::Markdown.read_yaml_for_doi_metadata(filepath, options.except(:number))
71
+
72
+ return "Error: required metadata missing" unless ["author", "title", "date", "summary"].all? { |k| metadata.key? k }
73
+
74
+ # read in optional yaml configuration file for site
75
+ sitepath = options[:sitepath] || ENV['SITE_SITEPATH']
76
+ site_options = sitepath.present? ? Bergamasco::Markdown.read_yaml(sitepath) : {}
77
+
78
+ # read in optional yaml configuration file for authors
79
+ authorpath = options[:authorpath] || ENV['SITE_AUTHORPATH']
80
+ author_options = authorpath.present? ? Bergamasco::Markdown.read_yaml(authorpath) : {}
81
+
82
+ # required metadata
83
+ prefix = options[:prefix] || ENV['PREFIX']
84
+ metadata["doi"] ||= encode_doi(prefix, options)
85
+
86
+ site_url = site_options["site_url"] || ENV['SITE_URL']
87
+ metadata["url"] ||= url_from_path(site_url, filepath)
88
+
89
+ metadata["creators"] = Array(metadata["author"]).map do |a|
90
+ author = author_options.fetch(a, {})
91
+ if author.present?
92
+ { given_name: author["given"],
93
+ family_name: author["family"],
94
+ orcid: author["orcid"] }
95
+ else
96
+ { literal: a }
97
+ end
98
+ end
99
+
100
+ metadata["publisher"] = site_options["site_title"] || ENV['SITE_TITLE']
101
+ metadata["publication_year"] = metadata["date"][0..3].to_i
102
+
103
+ metadata["type"] ||= site_options["site_default_type"] || ENV['SITE_DEFAULT_TYPE'] || "BlogPosting"
104
+ resource_type_general = metadata["type"] == "Dataset" ? "Dataset" : "Text"
105
+
106
+ metadata["resource_type"] = { value: metadata["type"],
107
+ resource_type_general: resource_type_general }
108
+
109
+ # recommended metadata
110
+ metadata["descriptions"] = [{ value: metadata["summary"],
111
+ description_type: "Abstract" }]
73
112
 
74
- creators = Array(metadata["author"])
113
+ # use default version 1.0
114
+ metadata["version"] ||= "1.0"
75
115
 
76
- publisher = options[:publisher] || ENV['SITE_TITLE']
77
- publication_year = metadata["date"][0..3].to_i
116
+ license_name = site_options.fetch("license", {}).fetch("name", nil) || ENV['SITE_LICENCE_NAME'] || "Creative Commons Attribution"
117
+ license_url = site_options.fetch("license", {}).fetch("url", nil) || ENV['SITE_LICENCE_URL'] || "https://creativecommons.org/licenses/by/4.0/"
118
+ metadata["rights_list"] = [{ value: license_name, rights_uri: license_url }]
78
119
 
79
- resource_type = metadata["type"] || options[:type] || ENV['SITE_DEFAULT_TYPE'] || "BlogPosting"
80
- resource_type_general = resource_type == "Dataset" ? "Dataset" : "Text"
120
+ metadata["subjects"] = Array(metadata["tags"]).select { |t| t != "featured" }
81
121
 
82
- license_name = options[:license_name] || ENV['SITE_LICENCE_NAME'] || "Creative Commons Attribution"
83
- license_url = options[:license_url] # || ENV['SITE_LICENCE_URL'] || "https://creativecommons.org/licenses/by/4.0/"
122
+ contributor = site_options["site_institution"] || ENV['SITE_INSTITUTION']
123
+ metadata["contributors"] = [{ literal: contributor, contributor_type: "HostingInstitution" }]
124
+
125
+ metadata = metadata.extract!(*%w(doi url creators title publisher
126
+ publication_year resource_type descriptions version rights_list subjects contributors
127
+ related_identifiers))
128
+ end
129
+
130
+ def url_from_path(site_url, filepath)
131
+ site_url.to_s.chomp("\\") + "/" + File.basename(filepath)[0..-9] + "/"
132
+ end
84
133
 
85
- descriptions = [{ value: metadata["summary"], description_type: "Abstract" }]
134
+ def create_work_from_metadata(metadata, options={})
135
+ work = Cirneco::Work.new(metadata)
86
136
 
87
- contributor = options[:hosting_institution] || ENV['SITE_HOSTING_INSTITUTION']
88
- contributors = [{ literal: contrbutor }]
137
+ filename = metadata["doi"].split("/", 2).last + ".xml"
138
+ IO.write(filename, work.data)
89
139
 
90
- Cirneco::Work.new(doi: metadata["doi"], creators: creators, title: metadata["title"], publisher: publisher, publication_year: publication_year, resource_type: { value: resource_type, resource_type_general: resource_type_general }, rights: [{ value: license_name, rights_uri: license_url }], subjects: Array(metadata["tags"], descriptions: descriptions, contributors: contributors) )
140
+ work
91
141
  end
92
142
  end
93
143
  end
@@ -1,3 +1,3 @@
1
1
  module Cirneco
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
data/lib/cirneco/work.rb CHANGED
@@ -11,26 +11,27 @@ module Cirneco
11
11
  include Cirneco::Api
12
12
  include Cirneco::Utils
13
13
 
14
- attr_accessor :doi, :creators, :title, :publisher, :publication_year, :resource_type, :version, :related_identifiers, :rights_list, :descriptions, :subjects, :url, :media, :username, :password, :validation_errors
14
+ attr_accessor :doi, :url, :creators, :title, :publisher, :publication_year, :resource_type, :version, :related_identifiers, :rights_list, :descriptions, :contributors, :subjects, :media, :username, :password, :validation_errors
15
+
16
+ def initialize(metadata, **options)
17
+ @doi = metadata.fetch("doi", nil)
18
+ @url = metadata.fetch("url", nil)
19
+ @creators = metadata.fetch("creators", nil)
20
+ @title = metadata.fetch("title", nil)
21
+ @publisher = metadata.fetch("publisher", nil)
22
+ @publication_year = metadata.fetch("publication_year", nil)
23
+ @resource_type = metadata.fetch("resource_type", nil)
24
+ @version = metadata.fetch("version", nil)
25
+ @rights_list = metadata.fetch("rights_list", nil)
26
+ @subjects = metadata.fetch("subjects", nil)
27
+ @descriptions = metadata.fetch("descriptions", nil)
28
+ @contributors = metadata.fetch("contributors", nil)
29
+ @related_identifiers = metadata.fetch("related_identifiers", nil)
15
30
 
16
- def initialize(doi:, creators:, title:, publisher:, publication_year:, resource_type:, **options)
17
- @doi = doi
18
- @creators = creators
19
- @title = title
20
- @publisher = publisher
21
- @publication_year = publication_year
22
- @resource_type = resource_type
23
-
24
- @url = options.fetch(:url, nil)
25
31
  @media = options.fetch(:media, nil)
26
32
 
27
33
  @username = options.fetch(:username, nil)
28
34
  @password = options.fetch(:password, nil)
29
-
30
- @version = options.fetch(:version, nil)
31
- @rights_list = options.fetch(:rights_list, nil)
32
- @descriptions = options.fetch(:descriptions, nil)
33
- @related_identifiers = options.fetch(:related_identifiers, nil)
34
35
  end
35
36
 
36
37
  SCHEMA = File.expand_path("../../../resources/kernel-4.0/metadata.xsd", __FILE__)
@@ -55,8 +56,10 @@ module Cirneco
55
56
  insert_titles(xml)
56
57
  insert_publisher(xml)
57
58
  insert_publication_year(xml)
58
- insert_subjects(xml)
59
59
  insert_resource_type(xml)
60
+ insert_subjects(xml)
61
+ insert_contributors(xml)
62
+ insert_related_identifiers(xml)
60
63
  insert_version(xml)
61
64
  insert_rights_list(xml)
62
65
  insert_descriptions(xml)
@@ -69,22 +72,35 @@ module Cirneco
69
72
  def insert_creators(xml)
70
73
  return nil unless creators.present?
71
74
 
72
- xml.send(:'creators') do
75
+ xml.creators do
73
76
  creators.each do |creator|
74
77
  xml.creator do
75
- insert_creator(xml, creator)
78
+ insert_person(xml, creator, "creator")
76
79
  end
77
80
  end
78
81
  end
79
82
  end
80
83
 
81
- def insert_creator(xml, creator)
82
- creator_name = [creator[:family_name], creator[:given_name], creator[:literal]].compact.join(", ")
84
+ def insert_contributors(xml)
85
+ return nil unless contributors.present?
83
86
 
84
- xml.send(:'creatorName', creator_name)
85
- xml.send(:'givenName', creator[:given_name]) if creator[:given_name].present?
86
- xml.send(:'familyName', creator[:family_name]) if creator[:family_name].present?
87
- xml.nameIdentifier(creator[:orcid], 'schemeURI' => 'http://orcid.org/', 'nameIdentifierScheme' => 'ORCID') if creator[:orcid].present?
87
+ xml.contributors do
88
+ contributors.each do |contributor|
89
+ xml.contributor("contributorType" => contributor[:contributor_type]) do
90
+ insert_person(xml, contributor, "contributor")
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ def insert_person(xml, person, type)
97
+ person_name = [person[:family_name], person[:given_name], person[:literal]].compact.join(", ")
98
+
99
+ xml.send(:'creatorName', person_name) if type == "creator"
100
+ xml.send(:'contributorName', person_name) if type == "contributor"
101
+ xml.send(:'givenName', person[:given_name]) if person[:given_name].present?
102
+ xml.send(:'familyName', person[:family_name]) if person[:family_name].present?
103
+ xml.nameIdentifier(person[:orcid], 'schemeURI' => 'http://orcid.org/', 'nameIdentifierScheme' => 'ORCID') if person[:orcid].present?
88
104
  end
89
105
 
90
106
  def insert_titles(xml)
@@ -125,6 +141,16 @@ module Cirneco
125
141
  xml.version(version)
126
142
  end
127
143
 
144
+ def insert_related_identifiers(xml)
145
+ return xml unless related_identifiers.present?
146
+
147
+ xml.relatedIdentifiers do
148
+ related_identifiers.each do |related_identifier|
149
+ xml.relatedIdentifier(related_identifier[:value], 'relatedIdentifierType' => related_identifier[:related_identifier_type], 'relationType' => related_identifier[:relation_type])
150
+ end
151
+ end
152
+ end
153
+
128
154
  def insert_rights_list(xml)
129
155
  return xml unless rights_list.present?
130
156
 
@@ -145,34 +171,6 @@ module Cirneco
145
171
  end
146
172
  end
147
173
 
148
- def insert_contributors(xml)
149
- return nil unless contributors.present?
150
-
151
- xml.send(:'work:contributors') do
152
- contributors.each do |contributor|
153
- xml.contributor do
154
- insert_contributor(xml, contributor)
155
- end
156
- end
157
- end
158
- end
159
-
160
- def insert_contributor(xml, contributor)
161
- if contributor[:orcid].present?
162
- xml.send(:'common:contributor-orcid') do
163
- xml.send(:'common:uri', contributor[:orcid])
164
- xml.send(:'common:path', contributor[:orcid][17..-1])
165
- xml.send(:'common:host', 'orcid.org')
166
- end
167
- end
168
- xml.send(:'credit-name', contributor[:credit_name])
169
- if contributor[:role]
170
- xml.send(:'contributor-attributes') do
171
- xml.send(:'contributor-role', contributor[:role])
172
- end
173
- end
174
- end
175
-
176
174
  def without_control(s)
177
175
  r = ''
178
176
  s.each_codepoint do |c|
data/spec/api_spec.rb CHANGED
@@ -2,12 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  describe Cirneco::Work, vcr: true, :order => :defined do
4
4
  let(:doi) { "10.23725/0000-03VC" }
5
+ let(:url) { "http://www.datacite.org" }
5
6
  let(:creators) { [{ given_name: "Elizabeth", family_name: "Miller", orcid: "0000-0001-5000-0007", affiliation: "DataCite" }] }
6
7
  let(:title) { "Full DataCite XML Example" }
7
8
  let(:publisher) { "DataCite" }
8
9
  let(:publication_year) { 2014 }
9
10
  let(:resource_type) { { value: "XML", resource_type_general: "Software" } }
10
- let(:url) { "http://www.datacite.org" }
11
+ let(:metadata) { { "doi" => doi,
12
+ "url" => url,
13
+ "creators" => creators,
14
+ "title" => title,
15
+ "publisher" => publisher,
16
+ "publication_year" => publication_year,
17
+ "resource_type" => resource_type } }
11
18
  let(:media) { [{ mime_type: "application/pdf", url:"http://www.datacite.org/cirneco-test.pdf" }]}
12
19
  let(:username) { ENV['MDS_USERNAME'] }
13
20
  let(:password) { ENV['MDS_PASSWORD'] }
@@ -15,16 +22,10 @@ describe Cirneco::Work, vcr: true, :order => :defined do
15
22
  let(:fixture_path) { "spec/fixtures/" }
16
23
  let(:samples_path) { "resources/kernel-4.0/samples/" }
17
24
 
18
- subject { Cirneco::Work.new(doi: doi,
19
- creators: creators,
20
- title: title,
21
- publisher: publisher,
22
- publication_year: publication_year,
23
- resource_type: resource_type,
24
- url: url,
25
- media: media,
26
- username: username,
27
- password: password) }
25
+ subject { Cirneco::Work.new(metadata,
26
+ media: media,
27
+ username: username,
28
+ password: password) }
28
29
 
29
30
  describe "Metadata API" do
30
31
  describe "get" do