cff 0.1.0 → 0.2.0
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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +12 -2
- data/cff.gemspec +3 -0
- data/lib/cff.rb +2 -0
- data/lib/cff/entity.rb +50 -5
- data/lib/cff/file.rb +1 -3
- data/lib/cff/model-part.rb +41 -0
- data/lib/cff/model.rb +76 -19
- data/lib/cff/person.rb +26 -6
- data/lib/cff/util.rb +41 -0
- data/lib/cff/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba4e9410b991789174bfa5cff1b448600aceb46a
|
4
|
+
data.tar.gz: ac13ec2b66c63edeaa5eb721b88fec6a4b7fd0da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 807b056534179b4ae578259ef0c8fcc0a6a07d2782b4b134f9a790e99a682a82c9c632008ac8e76afbdd238b060f13c583b30bdb8b1c30c30a6c471230bf9661
|
7
|
+
data.tar.gz: 2caf814fc16b88fc4d9d70ce664d9a233e258c4460cce6547cca02fe424a5ee4d8d0fcc0bc2309045477901130f0cad97f5fbfce9aaba3b0067ecc4113c1a1b8
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
A Ruby library for manipulating CITATION.cff files.
|
5
5
|
|
6
|
+
[](https://badge.fury.io/rb/cff)
|
6
7
|
[](https://travis-ci.org/hainesr/ruby-cff)
|
7
8
|
[](https://codeclimate.com/github/hainesr/ruby-cff/maintainability)
|
8
9
|
[](https://coveralls.io/github/hainesr/ruby-cff)
|
@@ -17,9 +18,12 @@ See the [CITATION.cff documentation](https://citation-file-format.github.io/) fo
|
|
17
18
|
|
18
19
|
```ruby
|
19
20
|
cff = CFF::Model.new("Ruby CFF Library")
|
20
|
-
cff.version = 0.1.0
|
21
|
+
cff.version = "0.1.0"
|
21
22
|
cff.date_released = Date.today
|
22
23
|
cff.authors << CFF::Person.new("Robert", "Haines")
|
24
|
+
cff.license = "Apache-2.0"
|
25
|
+
cff.keywords << "ruby" << "credit" << "citation"
|
26
|
+
cff.repository_artifact = "https://rubygems.org/gems/cff"
|
23
27
|
|
24
28
|
CFF::File.write("CITATION.cff", cff)
|
25
29
|
```
|
@@ -31,10 +35,16 @@ cff-version: 1.0.3
|
|
31
35
|
message: If you use this software in your work, please cite it using the following metadata
|
32
36
|
title: Ruby CFF Library
|
33
37
|
version: 0.1.0
|
34
|
-
date-released: 2018-02-
|
38
|
+
date-released: 2018-02-24
|
39
|
+
license: Apache-2.0
|
40
|
+
repository-artifact: https://rubygems.org/gems/cff
|
35
41
|
authors:
|
36
42
|
- family-names: Haines
|
37
43
|
given-names: Robert
|
44
|
+
keywords:
|
45
|
+
- ruby
|
46
|
+
- credit
|
47
|
+
- citation
|
38
48
|
```
|
39
49
|
|
40
50
|
### Licence
|
data/cff.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.summary = "A Ruby library for manipulating CITATION.cff files."
|
26
26
|
spec.description = "See https://citation-file-format.github.io/ for more info."
|
27
27
|
spec.homepage = "https://github.com/hainesr/ruby-cff"
|
28
|
+
spec.license = "Apache-2.0"
|
28
29
|
|
29
30
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
30
31
|
f.match(%r{^(test|spec|features)/})
|
@@ -33,6 +34,8 @@ Gem::Specification.new do |spec|
|
|
33
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
35
|
spec.require_paths = ["lib"]
|
35
36
|
|
37
|
+
spec.required_ruby_version = ">= 2.2.0"
|
38
|
+
|
36
39
|
spec.add_development_dependency "bundler", "~> 1.16"
|
37
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
38
41
|
spec.add_development_dependency "minitest", "~> 5.0"
|
data/lib/cff.rb
CHANGED
data/lib/cff/entity.rb
CHANGED
@@ -18,17 +18,62 @@ module CFF
|
|
18
18
|
# An Entity can represent different types of entities, e.g., a publishing
|
19
19
|
# company, or conference. Like a Person, an Entity might have a number of
|
20
20
|
# roles, such as author, contact, editor, etc.
|
21
|
-
class Entity
|
21
|
+
class Entity < ModelPart
|
22
22
|
|
23
|
-
|
23
|
+
ALLOWED_FIELDS = [
|
24
|
+
'address',
|
25
|
+
'city',
|
26
|
+
'country',
|
27
|
+
'email',
|
28
|
+
'date-end',
|
29
|
+
'date-start',
|
30
|
+
'fax',
|
31
|
+
'location',
|
32
|
+
'name',
|
33
|
+
'orcid',
|
34
|
+
'post-code',
|
35
|
+
'region',
|
36
|
+
'tel',
|
37
|
+
'website'
|
38
|
+
].freeze # :nodoc:
|
24
39
|
|
25
40
|
# :call-seq:
|
26
41
|
# new(name) -> Entity
|
27
42
|
#
|
28
43
|
# Create a new Entity with the supplied name.
|
29
|
-
def initialize(
|
30
|
-
|
31
|
-
|
44
|
+
def initialize(param)
|
45
|
+
if Hash === param
|
46
|
+
super(param)
|
47
|
+
else
|
48
|
+
@fields = Hash.new('')
|
49
|
+
@fields['name'] = param
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# :call-seq:
|
54
|
+
# date_end = date
|
55
|
+
#
|
56
|
+
# Set the `date-end` field. If a non-Date object is passed in it will
|
57
|
+
# be parsed into a Date.
|
58
|
+
def date_end=(date)
|
59
|
+
unless Date === date
|
60
|
+
date = Date.parse(date)
|
61
|
+
end
|
62
|
+
|
63
|
+
@fields['date-end'] = date
|
64
|
+
end
|
65
|
+
|
66
|
+
# :call-seq:
|
67
|
+
# date_start = date
|
68
|
+
#
|
69
|
+
# Set the `date-start` field. If a non-Date object is passed in it will
|
70
|
+
# be parsed into a Date.
|
71
|
+
def date_start=(date)
|
72
|
+
unless Date === date
|
73
|
+
date = Date.parse(date)
|
74
|
+
end
|
75
|
+
|
76
|
+
@fields['date-start'] = date
|
32
77
|
end
|
33
78
|
|
34
79
|
end
|
data/lib/cff/file.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (c) 2018 Robert Haines.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
#
|
16
|
+
module CFF
|
17
|
+
|
18
|
+
# :stopdoc:
|
19
|
+
class ModelPart
|
20
|
+
include Util
|
21
|
+
|
22
|
+
attr_reader :fields
|
23
|
+
|
24
|
+
def initialize(fields)
|
25
|
+
@fields = fields
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(name, *args) # :nodoc:
|
29
|
+
n = method_to_field(name.id2name)
|
30
|
+
super unless self.class::ALLOWED_FIELDS.include?(n.chomp('='))
|
31
|
+
|
32
|
+
if n.end_with?('=')
|
33
|
+
@fields[n.chomp('=')] = args[0] || ''
|
34
|
+
else
|
35
|
+
@fields[n]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
# :startdoc:
|
41
|
+
end
|
data/lib/cff/model.rb
CHANGED
@@ -19,15 +19,24 @@ module CFF
|
|
19
19
|
# accessed direcly, or via File.
|
20
20
|
class Model
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
include Util
|
23
|
+
|
24
|
+
ALLOWED_FIELDS = [
|
25
|
+
'abstract',
|
26
|
+
'cff-version',
|
27
|
+
'commit',
|
28
|
+
'date-released',
|
29
|
+
'doi',
|
30
|
+
'license',
|
31
|
+
'license-url',
|
32
|
+
'message',
|
33
|
+
'repository',
|
34
|
+
'repository-artifact',
|
35
|
+
'repository-code',
|
36
|
+
'title',
|
37
|
+
'url',
|
38
|
+
'version'
|
39
|
+
].freeze # :nodoc:
|
31
40
|
|
32
41
|
# The default message to use if none is explicitly set.
|
33
42
|
DEFAULT_MESSAGE = "If you use this software in your work, please cite it using the following metadata"
|
@@ -37,16 +46,18 @@ module CFF
|
|
37
46
|
#
|
38
47
|
# Initialize a new Model with the supplied title.
|
39
48
|
def initialize(param)
|
49
|
+
@authors = []
|
50
|
+
@contact = []
|
51
|
+
@keywords = []
|
52
|
+
|
40
53
|
if Hash === param
|
41
|
-
|
54
|
+
build_model(param)
|
42
55
|
else
|
43
56
|
@fields = Hash.new('')
|
44
57
|
@fields['cff-version'] = DEFAULT_SPEC_VERSION
|
45
58
|
@fields['message'] = DEFAULT_MESSAGE
|
46
59
|
@fields['title'] = param
|
47
60
|
end
|
48
|
-
|
49
|
-
@authors = []
|
50
61
|
end
|
51
62
|
|
52
63
|
# :call-seq:
|
@@ -64,6 +75,21 @@ module CFF
|
|
64
75
|
@authors
|
65
76
|
end
|
66
77
|
|
78
|
+
# :call-seq:
|
79
|
+
# contact -> Array
|
80
|
+
#
|
81
|
+
# Return the list of contacts for this citation. To add a contact to the
|
82
|
+
# list, use:
|
83
|
+
#
|
84
|
+
# ```
|
85
|
+
# model.contact << contact
|
86
|
+
# ```
|
87
|
+
#
|
88
|
+
# Contacts can be a Person or Entity.
|
89
|
+
def contact
|
90
|
+
@contact
|
91
|
+
end
|
92
|
+
|
67
93
|
# :call-seq:
|
68
94
|
# date_released = date
|
69
95
|
#
|
@@ -77,6 +103,21 @@ module CFF
|
|
77
103
|
@fields['date-released'] = date
|
78
104
|
end
|
79
105
|
|
106
|
+
# :call-seq:
|
107
|
+
# keywords -> Array
|
108
|
+
#
|
109
|
+
# Return the list of keywords for this citation. To add a keyword to the
|
110
|
+
# list, use:
|
111
|
+
#
|
112
|
+
# ```
|
113
|
+
# model.keywords << keyword
|
114
|
+
# ```
|
115
|
+
#
|
116
|
+
# Keywords will be converted to Strings on output to a CFF file.
|
117
|
+
def keywords
|
118
|
+
@keywords
|
119
|
+
end
|
120
|
+
|
80
121
|
# :call-seq:
|
81
122
|
# version = version
|
82
123
|
#
|
@@ -87,17 +128,17 @@ module CFF
|
|
87
128
|
|
88
129
|
def to_yaml # :nodoc:
|
89
130
|
fields = @fields.dup
|
90
|
-
fields['authors'] = @authors
|
91
|
-
|
92
|
-
|
131
|
+
fields['authors'] = array_field_to_yaml(@authors) unless @authors.empty?
|
132
|
+
fields['contact'] = array_field_to_yaml(@contact) unless @contact.empty?
|
133
|
+
fields['keywords'] = @keywords.map { |k| k.to_s } unless @keywords.empty?
|
93
134
|
|
94
135
|
YAML.dump fields, :line_width => -1, :indentation => 2
|
95
136
|
end
|
96
137
|
|
97
138
|
def method_missing(name, *args) # :nodoc:
|
98
|
-
super unless ALLOWED_METHODS.include?(name)
|
99
|
-
|
100
139
|
n = method_to_field(name.id2name)
|
140
|
+
super unless ALLOWED_FIELDS.include?(n.chomp('='))
|
141
|
+
|
101
142
|
if n.end_with?('=')
|
102
143
|
@fields[n.chomp('=')] = args[0] || ''
|
103
144
|
else
|
@@ -107,8 +148,24 @@ module CFF
|
|
107
148
|
|
108
149
|
private
|
109
150
|
|
110
|
-
def
|
111
|
-
|
151
|
+
def build_model(fields)
|
152
|
+
build_entity_collection(@authors, fields['authors'])
|
153
|
+
build_entity_collection(@contact, fields['contact'])
|
154
|
+
@keywords = fields['keywords']
|
155
|
+
|
156
|
+
@fields = delete_from_hash(fields, 'authors', 'contact', 'keywords')
|
157
|
+
end
|
158
|
+
|
159
|
+
def build_entity_collection(field, source)
|
160
|
+
source.each do |s|
|
161
|
+
field << (s.has_key?('given-names') ? Person.new(s) : Entity.new(s))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def array_field_to_yaml(field)
|
166
|
+
field.reject do |f|
|
167
|
+
!f.respond_to?(:fields)
|
168
|
+
end.map { |f| f.fields }
|
112
169
|
end
|
113
170
|
|
114
171
|
end
|
data/lib/cff/person.rb
CHANGED
@@ -17,18 +17,38 @@ module CFF
|
|
17
17
|
|
18
18
|
# A Person represents a person in a CITATION.cff file. A Person might have a
|
19
19
|
# number of roles, such as author, contact, editor, etc.
|
20
|
-
class Person
|
20
|
+
class Person < ModelPart
|
21
21
|
|
22
|
-
|
22
|
+
ALLOWED_FIELDS = [
|
23
|
+
'address',
|
24
|
+
'affiliation',
|
25
|
+
'city',
|
26
|
+
'country',
|
27
|
+
'email',
|
28
|
+
'family-names',
|
29
|
+
'fax',
|
30
|
+
'given-names',
|
31
|
+
'name-particle',
|
32
|
+
'name-suffix',
|
33
|
+
'orcid',
|
34
|
+
'post-code',
|
35
|
+
'region',
|
36
|
+
'tel',
|
37
|
+
'website'
|
38
|
+
].freeze # :nodoc:
|
23
39
|
|
24
40
|
# :call-seq:
|
25
41
|
# new(given_name, family_name) -> Person
|
26
42
|
#
|
27
43
|
# Create a new Person with the supplied given and family names.
|
28
|
-
def initialize(
|
29
|
-
|
30
|
-
|
31
|
-
|
44
|
+
def initialize(param, *more)
|
45
|
+
if Hash === param
|
46
|
+
super(param)
|
47
|
+
else
|
48
|
+
@fields = Hash.new('')
|
49
|
+
@fields['family-names'] = more[0]
|
50
|
+
@fields['given-names'] = param
|
51
|
+
end
|
32
52
|
end
|
33
53
|
|
34
54
|
end
|
data/lib/cff/util.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (c) 2018 Robert Haines.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
#
|
16
|
+
module CFF
|
17
|
+
|
18
|
+
# Utility methods useful throughout the rest of the CFF library.
|
19
|
+
module Util
|
20
|
+
|
21
|
+
# :call-seq:
|
22
|
+
# delete_from_hash(hash, keys...) -> Hash
|
23
|
+
#
|
24
|
+
# Returns a hash that includes everything but the given keys.
|
25
|
+
def delete_from_hash(hash, *keys)
|
26
|
+
h = hash.dup
|
27
|
+
keys.each { |key| h.delete(key) }
|
28
|
+
h
|
29
|
+
end
|
30
|
+
|
31
|
+
# :call-seq:
|
32
|
+
# method_to_field(name) -> converted name
|
33
|
+
#
|
34
|
+
# Return the supplied name with underscores converted to dashes.
|
35
|
+
def method_to_field(name)
|
36
|
+
name.gsub('_', '-')
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/cff/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Haines
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,11 +116,14 @@ files:
|
|
116
116
|
- lib/cff.rb
|
117
117
|
- lib/cff/entity.rb
|
118
118
|
- lib/cff/file.rb
|
119
|
+
- lib/cff/model-part.rb
|
119
120
|
- lib/cff/model.rb
|
120
121
|
- lib/cff/person.rb
|
122
|
+
- lib/cff/util.rb
|
121
123
|
- lib/cff/version.rb
|
122
124
|
homepage: https://github.com/hainesr/ruby-cff
|
123
|
-
licenses:
|
125
|
+
licenses:
|
126
|
+
- Apache-2.0
|
124
127
|
metadata: {}
|
125
128
|
post_install_message:
|
126
129
|
rdoc_options: []
|
@@ -130,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
133
|
requirements:
|
131
134
|
- - ">="
|
132
135
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
136
|
+
version: 2.2.0
|
134
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
138
|
requirements:
|
136
139
|
- - ">="
|