cff 0.9.0 → 1.0.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.
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Haines
8
8
  - The Ruby Citation File Format Developers
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-08-18 00:00:00.000000000 Z
12
+ date: 2022-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.20.0
20
+ version: 0.20.4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.20.0
27
+ version: 0.20.4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: language_list
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.2'
34
+ version: 1.2.1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.2'
41
+ version: 1.2.1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: minitest
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '5.14'
48
+ version: 5.16.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '5.14'
55
+ version: 5.16.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -73,84 +73,84 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '6.3'
76
+ version: 6.4.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '6.3'
83
+ version: 6.4.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rubocop
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '1.15'
90
+ version: 1.35.0
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.15'
97
+ version: 1.35.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rubocop-minitest
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.13'
104
+ version: 0.21.0
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0.13'
111
+ version: 0.21.0
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: rubocop-performance
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: 1.11.0
118
+ version: 1.14.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: 1.11.0
125
+ version: 1.14.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rubocop-rake
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: 0.5.0
132
+ version: 0.6.0
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: 0.5.0
139
+ version: 0.6.0
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: simplecov
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - "~>"
144
+ - - '='
145
145
  - !ruby/object:Gem::Version
146
- version: 0.20.0
146
+ version: 0.18.3
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - "~>"
151
+ - - '='
152
152
  - !ruby/object:Gem::Version
153
- version: 0.20.0
153
+ version: 0.18.3
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: simplecov-lcov
156
156
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +189,7 @@ files:
189
189
  - CHANGES.md
190
190
  - CITATION.cff
191
191
  - CODE_OF_CONDUCT.md
192
+ - CONTRIBUTING.md
192
193
  - Gemfile
193
194
  - LICENCE
194
195
  - README.md
@@ -197,22 +198,26 @@ files:
197
198
  - bin/setup
198
199
  - cff.gemspec
199
200
  - lib/cff.rb
201
+ - lib/cff/citable.rb
200
202
  - lib/cff/entity.rb
201
203
  - lib/cff/errors.rb
202
204
  - lib/cff/file.rb
203
- - lib/cff/formatter/apa_formatter.rb
204
- - lib/cff/formatter/bibtex_formatter.rb
205
- - lib/cff/formatter/formatter.rb
205
+ - lib/cff/formatters.rb
206
+ - lib/cff/formatters/all.rb
207
+ - lib/cff/formatters/apalike.rb
208
+ - lib/cff/formatters/bibtex.rb
209
+ - lib/cff/formatters/formatter.rb
206
210
  - lib/cff/identifier.rb
211
+ - lib/cff/index.rb
207
212
  - lib/cff/licensable.rb
208
- - lib/cff/model.rb
209
213
  - lib/cff/model_part.rb
210
214
  - lib/cff/person.rb
211
215
  - lib/cff/reference.rb
216
+ - lib/cff/schema.rb
217
+ - lib/cff/schemas/1.2.0.json
212
218
  - lib/cff/util.rb
213
219
  - lib/cff/validatable.rb
214
220
  - lib/cff/version.rb
215
- - lib/schema/1.2.0.json
216
221
  homepage: https://github.com/citation-file-format/ruby-cff
217
222
  licenses:
218
223
  - Apache-2.0
@@ -221,7 +226,8 @@ metadata:
221
226
  changelog_uri: https://github.com/citation-file-format/ruby-cff/blob/main/CHANGES.md
222
227
  documentation_uri: https://citation-file-format.github.io/ruby-cff/
223
228
  source_code_uri: https://github.com/citation-file-format/ruby-cff
224
- post_install_message:
229
+ rubygems_mfa_required: 'true'
230
+ post_install_message:
225
231
  rdoc_options: []
226
232
  require_paths:
227
233
  - lib
@@ -236,8 +242,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
242
  - !ruby/object:Gem::Version
237
243
  version: '0'
238
244
  requirements: []
239
- rubygems_version: 3.1.4
240
- signing_key:
245
+ rubygems_version: 3.1.6
246
+ signing_key:
241
247
  specification_version: 4
242
248
  summary: A Ruby library for manipulating CITATION.cff files.
243
249
  test_files: []
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- ##
18
- module CFF
19
- # Generates an APALIKE citation string
20
- class ApaFormatter < Formatter # :nodoc:
21
-
22
- def self.format(model:, preferred_citation: true) # rubocop:disable Metrics/AbcSize
23
- model = select_and_check_model(model, preferred_citation)
24
- return if model.nil?
25
-
26
- output = []
27
- output << combine_authors(
28
- model.authors.map { |author| format_author(author) }
29
- )
30
-
31
- _, year = month_and_year_from_model(model)
32
- output << "(#{year})" unless year.empty?
33
-
34
- version = " (Version #{model.version})" unless model.version.to_s.empty?
35
- output << "#{model.title}#{version}#{software_label(model)}"
36
- output << publication_data_from_model(model)
37
- output << url(model)
38
-
39
- output.reject(&:empty?).join('. ')
40
- end
41
-
42
- def self.publication_data_from_model(model)
43
- return '' unless model.respond_to?(:journal) && !model.journal.empty?
44
-
45
- vol = model.volume.to_s.empty? ? '' : "#{model.volume}(#{model.issue})"
46
-
47
- [model.journal, vol, model.start.to_s].reject(&:empty?).join(', ')
48
- end
49
-
50
- # Prefer a DOI over the other URI options.
51
- def self.url(model)
52
- model.doi.empty? ? super : "https://doi.org/#{model.doi}"
53
- end
54
-
55
- def self.software_label(model)
56
- return '' if model.is_a?(Reference) && !model.type.include?('software')
57
-
58
- ' [Computer software]'
59
- end
60
-
61
- def self.combine_authors(authors)
62
- return authors[0].chomp('.') if authors.length == 1
63
-
64
- "#{authors[0..-2].join(', ')}, & #{authors[-1]}".chomp('.')
65
- end
66
-
67
- def self.format_author(author)
68
- return author.name if author.is_a?(Entity)
69
-
70
- particle =
71
- author.name_particle.empty? ? '' : "#{author.name_particle} "
72
- suffix = author.name_suffix.empty? ? '.' : "., #{author.name_suffix}"
73
-
74
- "#{particle}#{author.family_names}, #{initials(author.given_names)}#{suffix}"
75
- end
76
- end
77
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- ##
18
- module CFF
19
- # Generates an BibTex citation string
20
- class BibtexFormatter < Formatter # :nodoc:
21
-
22
- def self.format(model:, preferred_citation: true) # rubocop:disable Metrics/AbcSize
23
- model = select_and_check_model(model, preferred_citation)
24
- return if model.nil?
25
-
26
- values = {}
27
- values['author'] = combine_authors(
28
- model.authors.map { |author| format_author(author) }
29
- )
30
- values['title'] = "{#{model.title}}"
31
-
32
- publication_data_from_model(model, values)
33
-
34
- month, year = month_and_year_from_model(model)
35
- values['month'] = month
36
- values['year'] = year
37
-
38
- values['url'] = url(model)
39
-
40
- values.reject! { |_, v| v.empty? }
41
- sorted_values = values.sort.map do |key, value|
42
- "#{key} = {#{value}}"
43
- end
44
- sorted_values.insert(0, generate_reference(values))
45
-
46
- "@#{bibtex_type(model)}{#{sorted_values.join(",\n")}\n}"
47
- end
48
-
49
- # Get various bits of information about the reference publication.
50
- # Reference: https://www.bibtex.com/format/
51
- def self.publication_data_from_model(model, fields)
52
- %w[doi journal volume].each do |field|
53
- fields[field] = model.send(field).to_s if model.respond_to?(field)
54
- end
55
-
56
- # BibTeX 'number' is CFF 'issue'.
57
- fields['number'] = model.issue.to_s if model.respond_to?(:issue)
58
-
59
- fields['pages'] = pages_from_model(model)
60
- end
61
-
62
- # CFF 'pages' is the number of pages, which has no equivalent in BibTeX.
63
- # Reference: https://www.bibtex.com/f/pages-field/
64
- def self.pages_from_model(model)
65
- return '' if !model.respond_to?(:start) || model.start.to_s.empty?
66
-
67
- start = model.start.to_s
68
- finish = model.end.to_s
69
- if finish.empty?
70
- start
71
- else
72
- start == finish ? start : "#{start}--#{finish}"
73
- end
74
- end
75
-
76
- # Do what we can to map between CFF reference types and bibtex types.
77
- # Reference: https://www.bibtex.com/e/entry-types/
78
- def self.bibtex_type(model)
79
- return 'misc' unless model.is_a?(Reference)
80
-
81
- case model.type
82
- when 'article', 'book', 'manual', 'unpublished'
83
- model.type
84
- when 'conference', 'proceedings'
85
- 'proceedings'
86
- when 'conference-paper'
87
- 'inproceedings'
88
- when 'magazine-article', 'newspaper-article'
89
- 'article'
90
- when 'pamphlet'
91
- 'booklet'
92
- else
93
- 'misc'
94
- end
95
- end
96
-
97
- def self.format_author(author)
98
- return "{#{author.name}}" if author.is_a?(Entity)
99
-
100
- particle =
101
- author.name_particle.empty? ? '' : "#{author.name_particle} "
102
-
103
- [
104
- "#{particle}#{author.family_names}",
105
- author.name_suffix,
106
- author.given_names
107
- ].reject(&:empty?).join(', ')
108
- end
109
-
110
- def self.combine_authors(authors)
111
- authors.join(' and ')
112
- end
113
-
114
- def self.generate_reference(fields)
115
- [
116
- fields['author'].split(',', 2)[0].tr(' -', '_'),
117
- fields['title'].split[0..2],
118
- fields['year']
119
- ].compact.join('_').tr('-$£%&(){}+!?/\\:;\'"~#', '')
120
- end
121
- end
122
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- ##
18
- module CFF
19
- # Formatter base class
20
- class Formatter # :nodoc:
21
-
22
- def self.select_and_check_model(model, preferred_citation)
23
- if preferred_citation && model.preferred_citation.is_a?(Reference)
24
- model = model.preferred_citation
25
- end
26
-
27
- # Safe to assume valid `Model`s and `Reference`s will have these fields.
28
- model.authors.empty? || model.title.empty? ? nil : model
29
- end
30
-
31
- def self.initials(name)
32
- name.split.map { |part| part[0].capitalize }.join('. ')
33
- end
34
-
35
- # Prefer `repository_code` over `url`
36
- def self.url(model)
37
- model.repository_code.empty? ? model.url : model.repository_code
38
- end
39
-
40
- def self.month_and_year_from_model(model)
41
- if model.respond_to?(:year)
42
- result = [model.month, model.year].map(&:to_s)
43
-
44
- return result unless result.any?(&:empty?)
45
- end
46
-
47
- month_and_year_from_date(model.date_released)
48
- end
49
-
50
- def self.month_and_year_from_date(value)
51
- if value.is_a?(Date)
52
- [value.month, value.year].map(&:to_s)
53
- else
54
- begin
55
- date = Date.parse(value.to_s)
56
- [date.month, date.year].map(&:to_s)
57
- rescue ArgumentError
58
- ['', '']
59
- end
60
- end
61
- end
62
- end
63
- end