cff 0.9.0 → 1.0.0

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: a3c050f5d10f432c5f693e34a3e357d6f6cb6354a34f1437e2d002d31260a668
4
+ data.tar.gz: 77a28d90a783419770aa706b033fc16895aa33762b1bf1e8d63f283e949b52b8
5
5
  SHA512:
6
- metadata.gz: 2834d89f3fac5714b9708cd4c15999c5df41c50bfc9bab3fa6b208cca46fff333b6d619fb7e84cb6faaec5a42219ae3a37db9830c2f788179a926d66e6ac1c33
7
- data.tar.gz: 82bc7dffa78909c49c0c035ab6b8823852a1ce5e8c9486ce81f09d7a88fb530c09e2a0c486274d282ae963a737bc6cef272dd1be00509c2d65053a6ff1f2c827
6
+ metadata.gz: 20af71ee0317e192bccd3cd2a4e8e2be39c8bab84b9c4c74571968b80d519d292b2b7f2564aa5786fe995fddedfa90edea76058e400bd0971b1d805e0256b9ab
7
+ data.tar.gz: e38acde51d42a67b37c197c9d03e55fbe2a55ec5f3ee2e2632c1842a6292035831ac55acfd8ded8812bda8dc06d96578b2dcf28870f29f1d6fc0c855df758ba8
data/CHANGES.md CHANGED
@@ -1,5 +1,78 @@
1
1
  # Changes log for the Ruby CFF Library
2
2
 
3
+ ## 1.0.0
4
+
5
+ * Add `type` to top-level CFF model.
6
+ * Correctly label datasets with APA-like formatter.
7
+ * Formatters: output a year, even if a month is not given.
8
+ * BibTeX: generalize getting simple publication data.
9
+ * BibTeX: generalize getting more complex publication data.
10
+ * BibTeX: get volume number from CFF `issue`.
11
+ * BibTeX: get publisher for a book.
12
+ * APA: get publisher for a book.
13
+ * BibTeX: add 'inproceedings' type for a preferred-citation.
14
+ * APA: add 'conference-paper' type for a preferred-citation.
15
+ * Generalize the `::pages_from_model` method.
16
+ * BibTeX: add address information where appropriate.
17
+ * BibTeX: use `software`, not `misc` where appropriate.
18
+ * BibTeX: add `version` field to `software` type.
19
+ * BibTeX: add `license` field to `software` type.
20
+ * Update README with the BibTeX formatter updates.
21
+ * Adding missing mapping for proceedings and conference
22
+ * BibTeX: add `manual` type for `preferred-citation`.
23
+ * BibTeX: add `doi` field to `manual` type.
24
+ * BibTeX: add `unpublished` type for `preferred-citation`.
25
+ * BibTeX: add `booklet` type for `preferred-citation`.
26
+ * BibTeX: add `techreport` type for `preferred-citation`.
27
+ * BibTeX: add the `institution` field for a `techreport`.
28
+ * APA: add the institution for a report, if possible.
29
+ * Clean up affiliations that include location in the report fixtures.
30
+ * Add `alias` field to `Entity`.
31
+ * Add a note to `Reference` about the `format` field.
32
+ * Ensure allowed fields in `Reference` are in alpha order.
33
+ * Add `term` field to `Reference`.
34
+ * Ensure allowed fields in `Entity` are in alpha order.
35
+ * Define `ModelPart#empty?`.
36
+ * Use `ModelPart#empty?` to simplify the formatter code.
37
+ * BibTeX: add the `note` field to all types.
38
+ * Prevent errors when cff is passed explicit `nil`s
39
+ * Update model part constructors for consistent behaviour.
40
+ * BibTeX: Use conference date if citing a conference paper.
41
+ * APA: Use conference date if citing a conference paper.
42
+ * APA: update range code to be more flexible.
43
+ * APA: add [Conference paper] label for conference papers.
44
+ * APA: handle date ranges with an earlier end date.
45
+ * Add `Util::transliterate` to normalise towards ASCII.
46
+ * Use the `transliterate` method to normalize citekeys.
47
+ * Add `Util::parameterize` to consolidate citekey code.
48
+ * Use the `parameterize` method to generate citekeys.
49
+ * Rename `generate_reference` -> `generate_citekey`.
50
+ * Only require language list if it is needed
51
+ * APA: don't output empty brackets if there's no issue.
52
+ * Formatters: use `date-published` for month/year values.
53
+ * Add a note to the README about BibTeX and APA standards.
54
+ * BibTeX: generalise author lists to actor lists.
55
+ * BibTeX: add `editor` field for `inproceedings` type.
56
+ * BibTeX: use `editors-series` if `editors` is not present.
57
+ * BibTeX: add `editor` field to `book` type.
58
+ * BibTeX: add `editor` field to `proceedings` type.
59
+ * Use the schema to determine the allowed fields within `Reference`.
60
+ * Use the schema to determine the allowed fields within `Person`.
61
+ * Use the schema to determine the allowed fields within `Entity`.
62
+ * Use the schema to determine the allowed fields within `Model`.
63
+ * Use the schema to determine the allowed fields within `Identifier`.
64
+ * Rename the `Model` class to `Index` which makes more sense.
65
+ * Add 'phdthesis' and 'mastersthesis' types for a preferred-citation.
66
+ * Add contribution guidelines.
67
+ * Handle 'in-press' in the formatters.
68
+ * Handle 'in-preparation' in the formatters.
69
+ * Handle 'submitted' in the formatters.
70
+ * Handle 'advance-online' in the formatters.
71
+ * Wholesale changes to isolate all the code from itself.
72
+ * Expand the range of tests, rubies and OSs in the CI.
73
+ * Update runtime gem dependencies.
74
+ * Implement an extensible formatter system.
75
+
3
76
  ## Version 0.9.0
4
77
 
5
78
  * 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.0).
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.0
25
25
  doi: 10.5281/zenodo.1184077
26
- date-released: 2021-08-18
26
+ date-released: 2022-10-09
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
@@ -7,6 +7,7 @@ A Ruby library for creating, editing, validating and converting CITATION.cff fil
7
7
  [![Gem Version](https://badge.fury.io/rb/cff.svg)](https://badge.fury.io/rb/cff)
8
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)
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,7 +15,7 @@ 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
 
@@ -22,10 +23,10 @@ See the [full API documentation](https://citation-file-format.github.io/ruby-cff
22
23
 
23
24
  ### Quick start
24
25
 
25
- You can quickly build and save a CFF model like this:
26
+ You can quickly build and save a CFF index like this:
26
27
 
27
28
  ```ruby
28
- model = CFF::Model.new('Ruby CFF Library') do |cff|
29
+ index = CFF::Index.new('Ruby CFF Library') do |cff|
29
30
  cff.version = CFF::VERSION
30
31
  cff.date_released = Date.today
31
32
  cff.authors << CFF::Person.new('Robert', 'Haines')
@@ -35,7 +36,7 @@ model = CFF::Model.new('Ruby CFF Library') do |cff|
35
36
  cff.repository_code = 'https://github.com/citation-file-format/ruby-cff'
36
37
  end
37
38
 
38
- CFF::File.write('CITATION.cff', model)
39
+ CFF::File.write('CITATION.cff', index)
39
40
  ```
40
41
 
41
42
  Which will produce a file that looks something like this:
@@ -51,14 +52,14 @@ keywords:
51
52
  - ruby
52
53
  - credit
53
54
  - citation
54
- version: 0.9.0
55
- date-released: 2021-08-18
55
+ version: 1.0.0
56
+ date-released: 2022-10-01
56
57
  license: Apache-2.0
57
58
  repository-artifact: https://rubygems.org/gems/cff
58
59
  repository-code: https://github.com/citation-file-format/ruby-cff
59
60
  ```
60
61
 
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:
62
+ `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
63
 
63
64
  ```ruby
64
65
  CFF::File.open('CITATION.cff') do |cff|
@@ -78,13 +79,13 @@ You can read a CFF file quickly with `CFF::File::read`:
78
79
  cff = CFF::File.read('CITATION.cff')
79
80
  ```
80
81
 
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`:
82
+ 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
83
 
83
84
  ```ruby
84
85
  cff_string = ::File.read('CITATION.cff')
85
- cff = CFF::Model.read(cff_string)
86
+ cff = CFF::Index.read(cff_string)
86
87
 
87
- CFF::Model.open(cff_string) do |cff|
88
+ CFF::Index.open(cff_string) do |cff|
88
89
  # Edit cff here...
89
90
  end
90
91
  ```
@@ -95,9 +96,9 @@ To quickly reference other software from your own CFF file, you can use `CFF::Re
95
96
  require 'open-uri'
96
97
 
97
98
  uri = 'https://raw.githubusercontent.com/citation-file-format/citation-file-format/main/CITATION.cff'
98
- other_cff = URI.open(uri).read
99
+ other_cff = URI(uri).open.read
99
100
 
100
- ref = CFF::Reference.from_cff(CFF::Model.read(other_cff))
101
+ ref = CFF::Reference.from_cff(CFF::Index.read(other_cff))
101
102
 
102
103
  CFF::File.open('CITATION.cff') do |cff|
103
104
  cff.references = [ref]
@@ -116,7 +117,7 @@ rescue CFF::ValidationError => e
116
117
  end
117
118
  ```
118
119
 
119
- Both `CFF::File` and `CFF::Model` have instance methods to validate CFF files as well:
120
+ Both `CFF::File` and `CFF::Index` have instance methods to validate CFF files as well:
120
121
 
121
122
  ```ruby
122
123
  cff = CFF::File.read('CITATION.cff')
@@ -129,7 +130,7 @@ end
129
130
 
130
131
  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
132
 
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.
133
+ 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
134
 
134
135
  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
136
 
@@ -155,19 +156,21 @@ Assuming the same CFF data as above, the two formats will look something like th
155
156
  #### BibTeX format
156
157
 
157
158
  ```tex
158
- @misc{Haines_Ruby_CFF_Library_2021,
159
+ @software{Haines_Ruby_CFF_Library_2022,
159
160
  author = {Haines, Robert},
160
- month = {8},
161
+ license = {Apache-2.0},
162
+ month = {10},
161
163
  title = {{Ruby CFF Library}},
162
164
  url = {https://github.com/citation-file-format/ruby-cff},
163
- year = {2021}
165
+ version = {1.0.0},
166
+ year = {2022}
164
167
  }
165
168
  ```
166
169
 
167
170
  #### APA-like format
168
171
 
169
172
  ```
170
- Haines, R. (2021). Ruby CFF Library (Version 0.9.0) [Computer software]. https://github.com/citation-file-format/ruby-cff
173
+ Haines, R. (2022). Ruby CFF Library (Version 1.0.0) [Computer software]. https://github.com/citation-file-format/ruby-cff
171
174
  ```
172
175
 
173
176
  #### Citing a paper rather than software
@@ -179,16 +182,19 @@ cff = CFF::File.read('CITATION.cff')
179
182
 
180
183
  cff.to_bibtex(preferred_citation: false)
181
184
  cff.to_apalike(preferred_citation: false)
182
-
183
185
  ```
184
186
 
185
187
  #### A note on citation formats
186
188
 
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).
189
+ 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
190
 
189
191
  ### Library versions
190
192
 
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.
193
+ 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.
194
+
195
+ ### Developing Ruby CFF
196
+
197
+ 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
198
 
193
199
  ### Licence
194
200
 
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