cff 1.0.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 734e15765062e2b7f6a00f25f89edec38c560be9c06605066dc8999ba6d46128
4
- data.tar.gz: 3ad6ed8ff24203d521b356c2f5b73c304e501522f8b43b3aa7b7b890c54d59d9
3
+ metadata.gz: '0685f4e60680971f1d131ee18722cd4989631cc223a192197a226cf18b8deca4'
4
+ data.tar.gz: 2bc27bb586bd0056a631b992a1da78befae597d8cc3815f5e124a72aa0e50180
5
5
  SHA512:
6
- metadata.gz: c873384b8a5dc7daea84ca0f184c457da397c4e21c9fbd64438328343bdd31481bfd7e4c48193fe074e8863961268f0adb72748e0aa73578cfffa80868366f56
7
- data.tar.gz: 1a9f094a9d8f7739b6a118fb1b789f54eb58e961eab94fb864a604d3736e9dbf0567031372debba753f68fe4d59f43c348687bb6ab1cf747aba045d7abe267ac
6
+ metadata.gz: 2b36c030c352a815045c8ee5464f2c445802e99ab44a7caab1503029f785f740673b273949faf530593141497e9948652886d2a2761ea1f8f66cb6707be7bcb5
7
+ data.tar.gz: 0325a6308c04c27213a16d54fb657f2b94c3fbb554e838ab469d3c10ef737e57bc3150b58e68550605b51aa2b971d5d6560933686d124be74aa746f1fb8c6669
data/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changes log for the Ruby CFF Library
2
2
 
3
+ ## 1.2.0
4
+
5
+ * Always treat dates as Ruby Date objects.
6
+ * BibTeX: escape special characters ($%&_#{}).
7
+
8
+ ## 1.1.0
9
+
10
+ * BibTeX: output months as three letter abbreviations.
11
+
3
12
  ## 1.0.1
4
13
 
5
14
  * Handle missing family or given names for authors.
data/CITATION.cff CHANGED
@@ -1,4 +1,4 @@
1
- # This CITATION.cff file was created by ruby-cff (v 1.0.1).
1
+ # This CITATION.cff file was created by ruby-cff (v 1.2.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: 1.0.1
24
+ version: 1.2.0
25
25
  doi: 10.5281/zenodo.1184077
26
- date-released: 2022-11-05
26
+ date-released: 2024-01-19
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/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-2022 The Ruby Citation File Format Developers.
189
+ Copyright (c) 2018-2024 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
@@ -203,7 +203,7 @@ cff.to_apalike(preferred_citation: false)
203
203
 
204
204
  #### A note on citation formats
205
205
 
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.
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.
207
207
 
208
208
  ### Library versions
209
209
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2024 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.
@@ -38,19 +38,30 @@ module CFF
38
38
  'unpublished' => %w[doi note!]
39
39
  }.freeze
40
40
 
41
- def self.format(model:, preferred_citation: true) # rubocop:disable Metrics/AbcSize
41
+ # Convert months to three letter abbreviations, as per
42
+ # https://www.bibtex.com/f/month-field/. Need to downcase from the
43
+ # built-in set.
44
+ MONTHS_MAP = Date::ABBR_MONTHNAMES.map do |month|
45
+ month.downcase unless month.nil?
46
+ end.freeze
47
+
48
+ # We need to escape these characters in titles and names, as per
49
+ # https://tex.stackexchange.com/questions/34580/escape-character-in-latex
50
+ ESCAPE_CHARS = Regexp.new(/([&%$#_{}])/)
51
+
52
+ def self.format(model:, preferred_citation: true) # rubocop:disable Metrics
42
53
  model = select_and_check_model(model, preferred_citation)
43
54
  return if model.nil?
44
55
 
45
56
  values = {}
46
57
  values['author'] = actor_list(model.authors)
47
- values['title'] = "{#{model.title}}"
58
+ values['title'] = "{#{l(model.title)}}"
48
59
 
49
60
  publication_type = bibtex_type(model)
50
61
  publication_data_from_model(model, publication_type, values)
51
62
 
52
63
  month, year = month_and_year_from_model(model)
53
- values['month'] = month
64
+ values['month'] = MONTHS_MAP[month.to_i] unless month.empty?
54
65
  values['year'] = year
55
66
 
56
67
  values['url'] = url(model)
@@ -59,7 +70,8 @@ module CFF
59
70
 
60
71
  values.reject! { |_, v| v.empty? }
61
72
  sorted_values = values.sort.map do |key, value|
62
- "#{key} = {#{value}}"
73
+ value = "{#{value}}" unless key == 'month'
74
+ "#{key} = #{value}"
63
75
  end
64
76
  sorted_values.insert(0, generate_citekey(values))
65
77
 
@@ -71,7 +83,7 @@ module CFF
71
83
  def self.publication_data_from_model(model, type, fields)
72
84
  ENTRY_TYPE_MAP[type].each do |field|
73
85
  if model.respond_to?(field)
74
- fields[field] = model.send(field).to_s
86
+ fields[field] = l(model.send(field).to_s)
75
87
  else
76
88
  field = field.chomp('!')
77
89
  fields[field] = send("#{field}_from_model", model)
@@ -100,9 +112,9 @@ module CFF
100
112
  # BibTeX 'institution' could be grabbed from an author's affiliation, or
101
113
  # provided explicitly.
102
114
  def self.institution_from_model(model)
103
- return model.institution.name unless model.institution.empty?
115
+ return l(model.institution.name) unless model.institution.empty?
104
116
 
105
- model.authors.first.affiliation
117
+ l(model.authors.first.affiliation)
106
118
  end
107
119
 
108
120
  # BibTeX 'school' is CFF 'institution'.
@@ -117,7 +129,7 @@ module CFF
117
129
 
118
130
  # BibTeX 'booktitle' is CFF 'collection-title'.
119
131
  def self.booktitle_from_model(model)
120
- model.collection_title
132
+ l(model.collection_title)
121
133
  end
122
134
 
123
135
  # BibTeX 'editor' is CFF 'editors' or 'editors-series'.
@@ -130,11 +142,11 @@ module CFF
130
142
  end
131
143
 
132
144
  def self.publisher_from_model(model)
133
- model.publisher.empty? ? '' : model.publisher.name
145
+ model.publisher.empty? ? '' : l(model.publisher.name)
134
146
  end
135
147
 
136
148
  def self.series_from_model(model)
137
- model.conference.empty? ? '' : model.conference.name
149
+ model.conference.empty? ? '' : l(model.conference.name)
138
150
  end
139
151
 
140
152
  # If we're citing a conference paper, try and use the date of the
@@ -174,9 +186,9 @@ module CFF
174
186
  end
175
187
  end
176
188
 
177
- def self.format_actor(author)
178
- return "{#{author.name}}" if author.is_a?(Entity)
179
- return author.alias if author.family_names.empty? && author.given_names.empty?
189
+ def self.format_actor(author) # rubocop:disable Metrics/AbcSize
190
+ return "{#{l(author.name)}}" if author.is_a?(Entity)
191
+ return l(author.alias) if author.family_names.empty? && author.given_names.empty?
180
192
 
181
193
  particle =
182
194
  author.name_particle.empty? ? '' : "#{author.name_particle} "
@@ -201,6 +213,12 @@ module CFF
201
213
 
202
214
  Util.parameterize(reference)
203
215
  end
216
+
217
+ # Escape a string to preserve special characters in LaTeX output.
218
+ # Used in many places, so short method name to preserve reading flow.
219
+ def self.l(string)
220
+ string.gsub(ESCAPE_CHARS, '\\\\\1')
221
+ end
204
222
  end
205
223
  end
206
224
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2023 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.
@@ -67,16 +67,9 @@ module CFF
67
67
  end
68
68
 
69
69
  def self.month_and_year_from_date(value)
70
- if value.is_a?(Date)
71
- [value.month, value.year].map(&:to_s)
72
- else
73
- begin
74
- date = Date.parse(value.to_s)
75
- [date.month, date.year].map(&:to_s)
76
- rescue ArgumentError
77
- ['', '']
78
- end
79
- end
70
+ return ['', ''] unless value.is_a?(Date)
71
+
72
+ [value.month, value.year].map(&:to_s)
80
73
  end
81
74
 
82
75
  # CFF 'pages' is the number of pages, which has no equivalent in BibTeX
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
3
+ # Copyright (c) 2018-2023 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.
@@ -59,23 +59,57 @@ module CFF
59
59
  symbols.each do |symbol|
60
60
  field = symbol.to_s.tr('_', '-')
61
61
 
62
- class_eval(
63
- # def date_end=(date)
64
- # date = (date.is_a?(Date) ? date.dup : Date.parse(date))
65
- #
66
- # @fields['date-end'] = date
67
- # end
68
- <<-END_SETTER, __FILE__, __LINE__ + 1
69
- def #{symbol}=(date)
70
- date = (date.is_a?(Date) ? date.dup : Date.parse(date))
71
-
72
- @fields['#{field}'] = date
73
- end
74
- END_SETTER
75
- )
62
+ date_getter(symbol, field)
63
+ date_setter(symbol, field)
76
64
  end
77
65
  end
78
66
 
67
+ def self.date_getter(symbol, field)
68
+ class_eval(
69
+ # def date_end
70
+ # date = @fields['date-end']
71
+ # return date if date.is_a?(Date)
72
+ #
73
+ # begin
74
+ # Date.parse(date)
75
+ # rescue
76
+ # ''
77
+ # end
78
+ # end
79
+ <<-END_GETTER, __FILE__, __LINE__ + 1
80
+ def #{symbol}
81
+ date = @fields['#{field}']
82
+ return date if date.is_a?(Date)
83
+
84
+ begin
85
+ Date.parse(date)
86
+ rescue
87
+ ''
88
+ end
89
+ end
90
+ END_GETTER
91
+ )
92
+ end
93
+
94
+ def self.date_setter(symbol, field)
95
+ class_eval(
96
+ # def date_end=(date)
97
+ # date = (date.is_a?(Date) ? date.dup : Date.parse(date))
98
+ #
99
+ # @fields['date-end'] = date
100
+ # end
101
+ <<-END_SETTER, __FILE__, __LINE__ + 1
102
+ def #{symbol}=(date)
103
+ date = (date.is_a?(Date) ? date.dup : Date.parse(date))
104
+
105
+ @fields['#{field}'] = date
106
+ end
107
+ END_SETTER
108
+ )
109
+ end
110
+
111
+ private_class_method :date_getter, :date_setter
112
+
79
113
  private
80
114
 
81
115
  def method_to_field(name)
data/lib/cff/version.rb CHANGED
@@ -17,7 +17,7 @@
17
17
  ##
18
18
  module CFF
19
19
  # :nodoc:
20
- VERSION = '1.0.1'
20
+ VERSION = '1.2.0'
21
21
  DEFAULT_SPEC_VERSION = '1.2.0'
22
22
  MIN_VALIDATABLE_VERSION = '1.2.0'
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Haines
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-05 00:00:00.000000000 Z
12
+ date: 2024-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema