cff 0.9.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4c306916ccaa887479febca758c7d8d5e9272229ee9eedb88663649e3d6c15c
4
- data.tar.gz: 798151267eba0eab166fc104660a5a87f15ecafdd336c0e9819ab9922a58b516
3
+ metadata.gz: 734e15765062e2b7f6a00f25f89edec38c560be9c06605066dc8999ba6d46128
4
+ data.tar.gz: 3ad6ed8ff24203d521b356c2f5b73c304e501522f8b43b3aa7b7b890c54d59d9
5
5
  SHA512:
6
- metadata.gz: 2834d89f3fac5714b9708cd4c15999c5df41c50bfc9bab3fa6b208cca46fff333b6d619fb7e84cb6faaec5a42219ae3a37db9830c2f788179a926d66e6ac1c33
7
- data.tar.gz: 82bc7dffa78909c49c0c035ab6b8823852a1ce5e8c9486ce81f09d7a88fb530c09e2a0c486274d282ae963a737bc6cef272dd1be00509c2d65053a6ff1f2c827
6
+ metadata.gz: c873384b8a5dc7daea84ca0f184c457da397c4e21c9fbd64438328343bdd31481bfd7e4c48193fe074e8863961268f0adb72748e0aa73578cfffa80868366f56
7
+ data.tar.gz: 1a9f094a9d8f7739b6a118fb1b789f54eb58e961eab94fb864a604d3736e9dbf0567031372debba753f68fe4d59f43c348687bb6ab1cf747aba045d7abe267ac
data/CHANGES.md CHANGED
@@ -1,5 +1,85 @@
1
1
  # Changes log for the Ruby CFF Library
2
2
 
3
+ ## 1.0.1
4
+
5
+ * Handle missing family or given names for authors.
6
+ * Handle authors with only an alias for a name.
7
+ * Add install instructions to the README.
8
+ * Add a note to the README re output format changes.
9
+
10
+ ## 1.0.0
11
+
12
+ * Add `type` to top-level CFF model.
13
+ * Correctly label datasets with APA-like formatter.
14
+ * Formatters: output a year, even if a month is not given.
15
+ * BibTeX: generalize getting simple publication data.
16
+ * BibTeX: generalize getting more complex publication data.
17
+ * BibTeX: get volume number from CFF `issue`.
18
+ * BibTeX: get publisher for a book.
19
+ * APA: get publisher for a book.
20
+ * BibTeX: add 'inproceedings' type for a preferred-citation.
21
+ * APA: add 'conference-paper' type for a preferred-citation.
22
+ * Generalize the `::pages_from_model` method.
23
+ * BibTeX: add address information where appropriate.
24
+ * BibTeX: use `software`, not `misc` where appropriate.
25
+ * BibTeX: add `version` field to `software` type.
26
+ * BibTeX: add `license` field to `software` type.
27
+ * Update README with the BibTeX formatter updates.
28
+ * Adding missing mapping for proceedings and conference
29
+ * BibTeX: add `manual` type for `preferred-citation`.
30
+ * BibTeX: add `doi` field to `manual` type.
31
+ * BibTeX: add `unpublished` type for `preferred-citation`.
32
+ * BibTeX: add `booklet` type for `preferred-citation`.
33
+ * BibTeX: add `techreport` type for `preferred-citation`.
34
+ * BibTeX: add the `institution` field for a `techreport`.
35
+ * APA: add the institution for a report, if possible.
36
+ * Clean up affiliations that include location in the report fixtures.
37
+ * Add `alias` field to `Entity`.
38
+ * Add a note to `Reference` about the `format` field.
39
+ * Ensure allowed fields in `Reference` are in alpha order.
40
+ * Add `term` field to `Reference`.
41
+ * Ensure allowed fields in `Entity` are in alpha order.
42
+ * Define `ModelPart#empty?`.
43
+ * Use `ModelPart#empty?` to simplify the formatter code.
44
+ * BibTeX: add the `note` field to all types.
45
+ * Prevent errors when cff is passed explicit `nil`s
46
+ * Update model part constructors for consistent behaviour.
47
+ * BibTeX: Use conference date if citing a conference paper.
48
+ * APA: Use conference date if citing a conference paper.
49
+ * APA: update range code to be more flexible.
50
+ * APA: add [Conference paper] label for conference papers.
51
+ * APA: handle date ranges with an earlier end date.
52
+ * Add `Util::transliterate` to normalise towards ASCII.
53
+ * Use the `transliterate` method to normalize citekeys.
54
+ * Add `Util::parameterize` to consolidate citekey code.
55
+ * Use the `parameterize` method to generate citekeys.
56
+ * Rename `generate_reference` -> `generate_citekey`.
57
+ * Only require language list if it is needed
58
+ * APA: don't output empty brackets if there's no issue.
59
+ * Formatters: use `date-published` for month/year values.
60
+ * Add a note to the README about BibTeX and APA standards.
61
+ * BibTeX: generalise author lists to actor lists.
62
+ * BibTeX: add `editor` field for `inproceedings` type.
63
+ * BibTeX: use `editors-series` if `editors` is not present.
64
+ * BibTeX: add `editor` field to `book` type.
65
+ * BibTeX: add `editor` field to `proceedings` type.
66
+ * Use the schema to determine the allowed fields within `Reference`.
67
+ * Use the schema to determine the allowed fields within `Person`.
68
+ * Use the schema to determine the allowed fields within `Entity`.
69
+ * Use the schema to determine the allowed fields within `Model`.
70
+ * Use the schema to determine the allowed fields within `Identifier`.
71
+ * Rename the `Model` class to `Index` which makes more sense.
72
+ * Add 'phdthesis' and 'mastersthesis' types for a preferred-citation.
73
+ * Add contribution guidelines.
74
+ * Handle 'in-press' in the formatters.
75
+ * Handle 'in-preparation' in the formatters.
76
+ * Handle 'submitted' in the formatters.
77
+ * Handle 'advance-online' in the formatters.
78
+ * Wholesale changes to isolate all the code from itself.
79
+ * Expand the range of tests, rubies and OSs in the CI.
80
+ * Update runtime gem dependencies.
81
+ * Implement an extensible formatter system.
82
+
3
83
  ## Version 0.9.0
4
84
 
5
85
  * Update to final released version of schema 1.2.0.
data/CITATION.cff CHANGED
@@ -1,4 +1,4 @@
1
- # This CITATION.cff file was created by ruby-cff (v 0.9.0).
1
+ # This CITATION.cff file was created by ruby-cff (v 1.0.1).
2
2
  # Gem: https://rubygems.org/gems/cff
3
3
  # CFF: https://citation-file-format.github.io/
4
4
 
@@ -21,9 +21,9 @@ keywords:
21
21
  - metadata
22
22
  - citation file format
23
23
  - CFF
24
- version: 0.9.0
24
+ version: 1.0.1
25
25
  doi: 10.5281/zenodo.1184077
26
- date-released: 2021-08-18
26
+ date-released: 2022-11-05
27
27
  license: Apache-2.0
28
28
  repository-artifact: https://rubygems.org/gems/cff
29
29
  repository-code: https://github.com/citation-file-format/ruby-cff
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,71 @@
1
+ # Contributing to the Ruby CFF Library
2
+ ## Introduction
3
+
4
+ **Thank you** for considering a contribution to the **Ruby CFF Library**!
5
+
6
+ If you intended to contribute to another part of the Citation File Format project, for example the Citation File Format specification itself, please contribute to the respective repository ([list of repositories in the `citation-file-format` GitHub organization](https://github.com/orgs/citation-file-format/repositories)).
7
+
8
+ **Please follow these guidelines.** Their purpose is to make both contributing and accepting contributions easier for all parties involved.
9
+
10
+ There are many ways to contribute, e.g.:
11
+
12
+ * Tell a friend or colleague about the Citation File Format and Ruby CFF, or tweet about it
13
+ * Write blog posts, tutorials, etc. about the Citation File Format and Ruby CFF
14
+ * Review the format and its schema and documentation
15
+ * Improve wording in any prose output, including the specifications
16
+ * Create a new, better version of the schema and specifications
17
+ * Improve automated tests, continuous integration, documentation, etc.
18
+
19
+ ## Ground Rules
20
+
21
+ Your contribution to Ruby CFF is valued, and it should be an enjoyable experience. To ensure this there is the Ruby CFF
22
+ [Code of Conduct](https://github.com/citation-file-format/ruby-cff/blob/main/CODE_OF_CONDUCT.md) which you are required to follow.
23
+
24
+ Please always start any contribution that will change the contents of this repository from [an issue](https://github.com/citation-file-format/ruby-cff/issues). This may mean [creating a new issue](https://github.com/citation-file-format/ruby-cff/issues/new) if it's something that hasn't been requested so far. This way,
25
+
26
+ * you can make sure that you don't invest your valuable time in something that may not be merged; and
27
+ * we can make sure that your contribution is something that will improve Ruby CFF, is in scope, and aligns with the roadmap for the Ruby CFF and the Citation File Format.
28
+
29
+ ## Your First Contribution
30
+
31
+ If you are unsure where to begin with your contribution to CFF, have a look at the [open issues in this repository](https://github.com/citation-file-format/ruby-cff/issues), and see if you can identify one that you would like to work on.
32
+
33
+ If you have never contributed to an open source project, you may find this tutorial helpful: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
34
+
35
+ ## Getting started
36
+
37
+ This is the workflow for contributions to this repository:
38
+
39
+ 1. Take note of the [code of conduct](https://github.com/citation-file-format/ruby-cff/blob/main/CODE_OF_CONDUCT.md)
40
+ 1. [Create a new issue](https://github.com/citation-file-format/ruby-cff/issues/new) if needs be, and discuss the changes you want to make with the maintainers and community
41
+ 1. Fork the repository
42
+ 1. Create a branch in your fork of the repository
43
+ 1. Make changes in the new branch in your fork
44
+ * Please don't forget tests!
45
+ * If you add any classes, modules, methods, attributes, or constants, please document them
46
+ 1. Create a pull request
47
+ 1. Address any comments that come up during review
48
+ 1. If and when your pull request has been merged, you can delete your branch (or the whole forked repository)
49
+
50
+ This workflow is loosely based on GitHub flow, and you can find more information in the [GitHub flow documentation](https://docs.github.com/en/get-started/quickstart/github-flow).
51
+
52
+ ### Working with tests and documentation
53
+
54
+ There is a comprehensive test suite for Ruby CFF, which also contains a collection of test `CITATION.cff` files - both valid and invalid. Please add tests (and new test `CITATION.cff` files if appropriate) for any new features you add, or bugs you squash. It is advised to run these tests locally on your computer prior to submitting a pull request. However, if that's not possible, you still can submit the pull request and later check the status of the tests for your pull request on GitHub.
55
+
56
+ To run the tests, assuming that you have all the dependencies installed, simply run:
57
+ ```shell
58
+ $ rake
59
+ ```
60
+
61
+ To rebuild the documentation, if you have added to it or changed it:
62
+ ```shell
63
+ $ rake rdoc
64
+ ```
65
+ Then load `html/index.html` into a Web browser and double check it.
66
+
67
+ ## FAQ
68
+
69
+ - **These guidelines do not address aspect XYZ! What should I do now?**
70
+
71
+ Please [submit an issue](https://github.com/citation-file-format/ruby-cff/issues/new), asking for clarification of and/or an addition to the guidelines.
data/LICENCE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
189
+ Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -5,8 +5,9 @@ A Ruby library for creating, editing, validating and converting CITATION.cff fil
5
5
 
6
6
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1184077.svg)](https://doi.org/10.5281/zenodo.1184077)
7
7
  [![Gem Version](https://badge.fury.io/rb/cff.svg)](https://badge.fury.io/rb/cff)
8
- [![Tests](https://github.com/citation-file-format/ruby-cff/actions/workflows/ruby.yml/badge.svg)](https://github.com/citation-file-format/ruby-cff/actions/workflows/ruby.yml)
8
+ [![Tests](https://github.com/citation-file-format/ruby-cff/actions/workflows/tests.yml/badge.svg)](https://github.com/citation-file-format/ruby-cff/actions/workflows/ruby.yml)
9
9
  [![Linter](https://github.com/citation-file-format/ruby-cff/actions/workflows/lint.yml/badge.svg)](https://github.com/citation-file-format/ruby-cff/actions/workflows/lint.yml)
10
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
10
11
  [![Maintainability](https://api.codeclimate.com/v1/badges/6bb4c661bfb4971260ba/maintainability)](https://codeclimate.com/github/citation-file-format/ruby-cff/maintainability)
11
12
  [![Coverage Status](https://coveralls.io/repos/github/citation-file-format/ruby-cff/badge.svg)](https://coveralls.io/github/citation-file-format/ruby-cff)
12
13
 
@@ -14,18 +15,35 @@ A Ruby library for creating, editing, validating and converting CITATION.cff fil
14
15
 
15
16
  This library provides a Ruby interface to create and edit Citation File Format (CFF) files. The resulting files can be validated against a formal schema to ensure correctness and can be output in a number of different citation-friendly formats.
16
17
 
17
- The primary API entry points are the `Model` and `File` classes.
18
+ The primary API entry points are the `Index` and `File` classes.
18
19
 
19
20
  See the [CITATION.cff documentation](https://citation-file-format.github.io/) for more details about the Citation File Format.
20
21
 
21
22
  See the [full API documentation](https://citation-file-format.github.io/ruby-cff/) for more details about Ruby CFF.
22
23
 
24
+ ### Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+ ```ruby
28
+ gem 'cff'
29
+ ```
30
+
31
+ And then execute:
32
+ ```shell
33
+ $ bundle
34
+ ```
35
+
36
+ Or install it yourself with:
37
+ ```shell
38
+ $ gem install cff
39
+ ```
40
+
23
41
  ### Quick start
24
42
 
25
- You can quickly build and save a CFF model like this:
43
+ You can quickly build and save a CFF index like this:
26
44
 
27
45
  ```ruby
28
- model = CFF::Model.new('Ruby CFF Library') do |cff|
46
+ index = CFF::Index.new('Ruby CFF Library') do |cff|
29
47
  cff.version = CFF::VERSION
30
48
  cff.date_released = Date.today
31
49
  cff.authors << CFF::Person.new('Robert', 'Haines')
@@ -35,7 +53,7 @@ model = CFF::Model.new('Ruby CFF Library') do |cff|
35
53
  cff.repository_code = 'https://github.com/citation-file-format/ruby-cff'
36
54
  end
37
55
 
38
- CFF::File.write('CITATION.cff', model)
56
+ CFF::File.write('CITATION.cff', index)
39
57
  ```
40
58
 
41
59
  Which will produce a file that looks something like this:
@@ -51,14 +69,14 @@ keywords:
51
69
  - ruby
52
70
  - credit
53
71
  - citation
54
- version: 0.9.0
55
- date-released: 2021-08-18
72
+ version: 1.0.0
73
+ date-released: 2022-10-01
56
74
  license: Apache-2.0
57
75
  repository-artifact: https://rubygems.org/gems/cff
58
76
  repository-code: https://github.com/citation-file-format/ruby-cff
59
77
  ```
60
78
 
61
- `CFF::File` can be used to create a file directly, and it exposes the underlying `CFF::Model` directly. If using a block with `CFF::File::open` the file will get written on closing it:
79
+ `CFF::File` can be used to create a file directly, and it exposes the underlying `CFF::Index` directly. If using a block with `CFF::File::open` the file will get written on closing it:
62
80
 
63
81
  ```ruby
64
82
  CFF::File.open('CITATION.cff') do |cff|
@@ -78,13 +96,13 @@ You can read a CFF file quickly with `CFF::File::read`:
78
96
  cff = CFF::File.read('CITATION.cff')
79
97
  ```
80
98
 
81
- And you can read a CFF file from memory with `CFF::Model::read` or `CFF::Model::open` - as with `CFF::File` a block can be passed in to `open`:
99
+ And you can read a CFF file from memory with `CFF::Index::read` or `CFF::Index::open` - as with `CFF::File` a block can be passed in to `open`:
82
100
 
83
101
  ```ruby
84
102
  cff_string = ::File.read('CITATION.cff')
85
- cff = CFF::Model.read(cff_string)
103
+ cff = CFF::Index.read(cff_string)
86
104
 
87
- CFF::Model.open(cff_string) do |cff|
105
+ CFF::Index.open(cff_string) do |cff|
88
106
  # Edit cff here...
89
107
  end
90
108
  ```
@@ -95,9 +113,9 @@ To quickly reference other software from your own CFF file, you can use `CFF::Re
95
113
  require 'open-uri'
96
114
 
97
115
  uri = 'https://raw.githubusercontent.com/citation-file-format/citation-file-format/main/CITATION.cff'
98
- other_cff = URI.open(uri).read
116
+ other_cff = URI(uri).open.read
99
117
 
100
- ref = CFF::Reference.from_cff(CFF::Model.read(other_cff))
118
+ ref = CFF::Reference.from_cff(CFF::Index.read(other_cff))
101
119
 
102
120
  CFF::File.open('CITATION.cff') do |cff|
103
121
  cff.references = [ref]
@@ -116,7 +134,7 @@ rescue CFF::ValidationError => e
116
134
  end
117
135
  ```
118
136
 
119
- Both `CFF::File` and `CFF::Model` have instance methods to validate CFF files as well:
137
+ Both `CFF::File` and `CFF::Index` have instance methods to validate CFF files as well:
120
138
 
121
139
  ```ruby
122
140
  cff = CFF::File.read('CITATION.cff')
@@ -129,7 +147,7 @@ end
129
147
 
130
148
  Non-bang methods (`validate`) return an array, with `true`/`false` at index 0 to indicate pass/fail, and an array of errors at index 1 (if any).
131
149
 
132
- Passing `fail_fast: true` (default: `false`) will cause the validator to abort on the first error it encounters and report just that. Only the instance methods on `CFF::File` and `CFF::Model` provide the `fail_fast` option.
150
+ Passing `fail_fast: true` (default: `false`) will cause the validator to abort on the first error it encounters and report just that. Only the instance methods on `CFF::File` and `CFF::Index` provide the `fail_fast` option.
133
151
 
134
152
  The validation methods (both class and instance) on `File` also validate the filename of a CFF file; in normal circumstances a CFF file should be named 'CITATION.cff'. You can switch this behaviour off by passing `fail_on_filename: false`. The non-bang methods (`validate`) on `File` return an extra value in the result array: `true`/`false` at index 2 to indicate whether the filename passed/failed validation.
135
153
 
@@ -155,19 +173,21 @@ Assuming the same CFF data as above, the two formats will look something like th
155
173
  #### BibTeX format
156
174
 
157
175
  ```tex
158
- @misc{Haines_Ruby_CFF_Library_2021,
176
+ @software{Haines_Ruby_CFF_Library_2022,
159
177
  author = {Haines, Robert},
160
- month = {8},
178
+ license = {Apache-2.0},
179
+ month = {10},
161
180
  title = {{Ruby CFF Library}},
162
181
  url = {https://github.com/citation-file-format/ruby-cff},
163
- year = {2021}
182
+ version = {1.0.0},
183
+ year = {2022}
164
184
  }
165
185
  ```
166
186
 
167
187
  #### APA-like format
168
188
 
169
189
  ```
170
- Haines, R. (2021). Ruby CFF Library (Version 0.9.0) [Computer software]. https://github.com/citation-file-format/ruby-cff
190
+ Haines, R. (2022). Ruby CFF Library (Version 1.0.0) [Computer software]. https://github.com/citation-file-format/ruby-cff
171
191
  ```
172
192
 
173
193
  #### Citing a paper rather than software
@@ -179,16 +199,21 @@ cff = CFF::File.read('CITATION.cff')
179
199
 
180
200
  cff.to_bibtex(preferred_citation: false)
181
201
  cff.to_apalike(preferred_citation: false)
182
-
183
202
  ```
184
203
 
185
204
  #### A note on citation formats
186
205
 
187
- Due to the different expectations of different publication venues, the citation text may need minor tweaking to be used in specific situations. If you spot a major, or general, error in the output please [let us know](https://github.com/citation-file-format/ruby-cff/issues).
206
+ Due to the different expectations of different publication venues, the citation text may need minor tweaking to be used in specific situations. If you spot a major, or general, error in the output do [let us know](https://github.com/citation-file-format/ruby-cff/issues), but please check against the [BibTex](https://www.bibtex.com/format/) and [APA](https://apastyle.apa.org/style-grammar-guidelines/references) standards first.
188
207
 
189
208
  ### Library versions
190
209
 
191
- Until this library reaches version 1.0.0 the API may be subject to breaking changes. When version 1.0.0 is released, then the principles of [semantic versioning](https://semver.org/) will be applied.
210
+ From version 1.0.0 onwards, the principles of [semantic versioning](https://semver.org/) are applied when numbering releases with new features or breaking changes.
211
+
212
+ Minor or stylistic changes to output formats are not considered "breaking" for the purposes of library versioning.
213
+
214
+ ### Developing Ruby CFF
215
+
216
+ Please see our [Code of Conduct](https://github.com/citation-file-format/ruby-cff/blob/main/CODE_OF_CONDUCT.md) and our [contributor guidelines](https://github.com/citation-file-format/ruby-cff/blob/main/CONTRIBUTING.md).
192
217
 
193
218
  ### Licence
194
219
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,24 +15,25 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'bundler/gem_tasks'
18
- require 'rake/testtask'
18
+ require 'minitest/test_task'
19
19
  require 'rdoc/task'
20
20
  require 'rubocop/rake_task'
21
21
 
22
22
  task default: :test
23
23
 
24
- Rake::TestTask.new(:test) do |t|
25
- t.libs << 'test'
26
- t.libs << 'lib'
27
- t.test_files = FileList['test/**/*_test.rb']
24
+ Minitest::TestTask.create do |test|
25
+ test.test_globs = 'test/**/*_test.rb'
28
26
  end
29
27
 
30
28
  RDoc::Task.new do |r|
31
29
  r.main = 'README.md'
32
- r.rdoc_files.include('README.md', 'LICENCE', 'CHANGES.md', 'lib/**/*.rb')
30
+ r.rdoc_files.include(
31
+ 'README.md', 'LICENCE', 'CODE_OF_CONDUCT.md', 'CONTRIBUTING.md',
32
+ 'CHANGES.md', 'lib/**/*.rb'
33
+ )
33
34
  r.options << '--markup=markdown'
34
35
  r.options << '--tab-width=2'
35
- r.options << "-t Ruby CFF Library version #{::CFF::VERSION}"
36
+ r.options << "-t Ruby CFF Library (version #{::CFF::VERSION})"
36
37
  end
37
38
 
38
39
  RuboCop::RakeTask.new
data/cff.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -35,7 +35,8 @@ Gem::Specification.new do |spec|
35
35
  'bug_tracker_uri' => 'https://github.com/citation-file-format/ruby-cff/issues',
36
36
  'changelog_uri' => 'https://github.com/citation-file-format/ruby-cff/blob/main/CHANGES.md',
37
37
  'documentation_uri' => 'https://citation-file-format.github.io/ruby-cff/',
38
- 'source_code_uri' => 'https://github.com/citation-file-format/ruby-cff'
38
+ 'source_code_uri' => 'https://github.com/citation-file-format/ruby-cff',
39
+ 'rubygems_mfa_required' => 'true'
39
40
  }
40
41
 
41
42
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -48,17 +49,17 @@ Gem::Specification.new do |spec|
48
49
 
49
50
  spec.required_ruby_version = '>= 2.6'
50
51
 
51
- spec.add_runtime_dependency 'json_schema', '~> 0.20.0'
52
- spec.add_runtime_dependency 'language_list', '~> 1.2'
52
+ spec.add_runtime_dependency 'json_schema', '~> 0.20.4'
53
+ spec.add_runtime_dependency 'language_list', '~> 1.2.1'
53
54
 
54
- spec.add_development_dependency 'minitest', '~> 5.14'
55
+ spec.add_development_dependency 'minitest', '~> 5.16.0'
55
56
  spec.add_development_dependency 'rake', '~> 13.0'
56
- spec.add_development_dependency 'rdoc', '~> 6.3'
57
- spec.add_development_dependency 'rubocop', '~> 1.15'
58
- spec.add_development_dependency 'rubocop-minitest', '~> 0.13'
59
- spec.add_development_dependency 'rubocop-performance', '~> 1.11.0'
60
- spec.add_development_dependency 'rubocop-rake', '~> 0.5.0'
61
- spec.add_development_dependency 'simplecov', '~> 0.20.0'
57
+ spec.add_development_dependency 'rdoc', '~> 6.4.0'
58
+ spec.add_development_dependency 'rubocop', '~> 1.35.0'
59
+ spec.add_development_dependency 'rubocop-minitest', '~> 0.21.0'
60
+ spec.add_development_dependency 'rubocop-performance', '~> 1.14.0'
61
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
62
+ spec.add_development_dependency 'simplecov', '0.18.3'
62
63
  spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
63
64
  spec.add_development_dependency 'test_construct', '~> 2.0'
64
65
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2022 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
+ require_relative 'formatters'
18
+
19
+ ##
20
+ module CFF
21
+ # Methods to enable turning a CFF model or file into a citation.
22
+ #
23
+ # The core functionality is in the `citation` method. In addition, each
24
+ # available output format has a `to_{format}` method generated for it as
25
+ # well, e.g. `to_bibtex` or `to_apalike`. These methods take a single
26
+ # parameter, `preferred_citation:`, which defaults to `true` as in the
27
+ # `citation` method.
28
+ module Citable
29
+ # :call-seq:
30
+ # citation(format, preferred_citation: true) -> String
31
+ #
32
+ # Output this Index in the specified format. Setting
33
+ # `preferred_citation: true` will honour the `preferred_citation` field in
34
+ # the index if one is present (default).
35
+ #
36
+ # `format` can be supplied as a String or a Symbol.
37
+ #
38
+ # Formats that are built-in to Ruby CFF are:
39
+ #
40
+ # * APAlike (e.g. `:apalike`, `'apalike'` or `'APAlike'`)
41
+ # * BibTeX (e.g. `:bibtex`, `'bibtex'` or `'BibTeX'`)
42
+ #
43
+ # *Note:* This method assumes that this Index is valid when called.
44
+ def citation(format, preferred_citation: true)
45
+ formatter = Formatters.formatter_for(format)
46
+ return '' if formatter.nil?
47
+
48
+ formatter.format(model: self, preferred_citation: preferred_citation)
49
+ end
50
+
51
+ def self.add_to_format_method(format) # :nodoc:
52
+ method = "to_#{format}"
53
+ return if method_defined?(method)
54
+
55
+ class_eval(
56
+ # def to_bibtex(preferred_citation: true)
57
+ # citation(:bibtex, preferred_citation: preferred_citation)
58
+ # end
59
+ <<-END_TO_FORMAT, __FILE__, __LINE__ + 1
60
+ def #{method}(preferred_citation: true)
61
+ citation(:#{format}, preferred_citation: preferred_citation)
62
+ end
63
+ END_TO_FORMAT
64
+ )
65
+ end
66
+
67
+ # Add the formatters we know about already upfront.
68
+ Formatters.formatters.each do |format|
69
+ add_to_format_method(format)
70
+ end
71
+ end
72
+ end
data/lib/cff/entity.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -14,9 +14,11 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require_relative 'model_part'
18
+ require_relative 'schema'
19
+
17
20
  ##
18
21
  module CFF
19
-
20
22
  # An Entity can represent different types of entities, e.g., a publishing
21
23
  # company, or conference. Like a Person, an Entity might have a number of
22
24
  # roles, such as author, contact, editor, etc.
@@ -28,11 +30,12 @@ module CFF
28
30
  # parentheses):
29
31
  #
30
32
  # * `address`
33
+ # * `alias`
31
34
  # * `city`
32
35
  # * `country`
33
- # * `email`
34
36
  # * `date_end` - *Note:* returns a `Date` object
35
37
  # * `date_start` - *Note:* returns a `Date` object
38
+ # * `email`
36
39
  # * `fax`
37
40
  # * `location`
38
41
  # * `name`
@@ -42,11 +45,9 @@ module CFF
42
45
  # * `tel`
43
46
  # * `website`
44
47
  class Entity < ModelPart
48
+ ALLOWED_FIELDS = SCHEMA_FILE['definitions']['entity']['properties'].keys.freeze # :nodoc:
45
49
 
46
- ALLOWED_FIELDS = [
47
- 'address', 'city', 'country', 'email', 'date-end', 'date-start', 'fax',
48
- 'location', 'name', 'orcid', 'post-code', 'region', 'tel', 'website'
49
- ].freeze # :nodoc:
50
+ attr_date :date_end, :date_start
50
51
 
51
52
  # :call-seq:
52
53
  # new(name) -> Entity
@@ -54,37 +55,16 @@ module CFF
54
55
  #
55
56
  # Create a new Entity with the supplied name.
56
57
  def initialize(param)
58
+ super()
59
+
57
60
  if param.is_a?(Hash)
58
61
  @fields = param
59
- @fields.default = ''
60
62
  else
61
- @fields = Hash.new('')
63
+ @fields = {}
62
64
  @fields['name'] = param
63
65
  end
64
66
 
65
67
  yield self if block_given?
66
68
  end
67
-
68
- # :call-seq:
69
- # date_end = date
70
- #
71
- # Set the `date-end` field. If a non-Date object is passed in it will
72
- # be parsed into a Date.
73
- def date_end=(date)
74
- date = Date.parse(date) unless date.is_a?(Date)
75
-
76
- @fields['date-end'] = date
77
- end
78
-
79
- # :call-seq:
80
- # date_start = date
81
- #
82
- # Set the `date-start` field. If a non-Date object is passed in it will
83
- # be parsed into a Date.
84
- def date_start=(date)
85
- date = Date.parse(date) unless date.is_a?(Date)
86
-
87
- @fields['date-start'] = date
88
- end
89
69
  end
90
70
  end
data/lib/cff/errors.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2021 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
16
16
 
17
17
  ##
18
18
  module CFF
19
-
20
19
  # Error is the base class for all errors raised by this library.
21
20
  class Error < RuntimeError
22
-
23
21
  def initialize(message = nil) # :nodoc:
24
22
  super
25
23
  end
@@ -31,9 +29,8 @@ module CFF
31
29
  #
32
30
  # Additionally, the `invalid_filename` flag is used to indicate whether the
33
31
  # CFF file is named correctly. This is only used when validating a File;
34
- # validating a Model directly will not set this flag to `true`.
32
+ # validating a Index directly will not set this flag to `true`.
35
33
  class ValidationError < Error
36
-
37
34
  # The list of JsonSchema::ValidationErrors found by the validator.
38
35
  attr_reader :errors
39
36