bibtex-ruby 4.4.7 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bibtex-ruby might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +23 -24
  3. data/History.txt +4 -0
  4. data/Rakefile +23 -25
  5. data/bibtex-ruby.gemspec +1 -1
  6. data/examples/bib2html.rb +5 -6
  7. data/examples/bib2yaml.rb +2 -2
  8. data/features/step_definitions/bibtex_steps.rb +3 -6
  9. data/features/step_definitions/name_steps.rb +1 -2
  10. data/lib/bibtex.rb +11 -13
  11. data/lib/bibtex/bibliography.rb +45 -58
  12. data/lib/bibtex/compatibility.rb +3 -5
  13. data/lib/bibtex/elements.rb +49 -42
  14. data/lib/bibtex/entry.rb +80 -84
  15. data/lib/bibtex/entry/citeproc_converter.rb +47 -52
  16. data/lib/bibtex/entry/rdf_converter.rb +97 -63
  17. data/lib/bibtex/error.rb +10 -11
  18. data/lib/bibtex/extensions.rb +2 -5
  19. data/lib/bibtex/filters.rb +4 -9
  20. data/lib/bibtex/filters/latex.rb +0 -2
  21. data/lib/bibtex/filters/linebreaks.rb +0 -2
  22. data/lib/bibtex/lexer.rb +81 -81
  23. data/lib/bibtex/names.rb +24 -28
  24. data/lib/bibtex/replaceable.rb +15 -17
  25. data/lib/bibtex/utilities.rb +5 -10
  26. data/lib/bibtex/value.rb +28 -34
  27. data/lib/bibtex/version.rb +6 -6
  28. data/test/benchmark.rb +20 -22
  29. data/test/bibtex/entry/test_rdf_converter.rb +3 -5
  30. data/test/bibtex/test_bibliography.rb +22 -35
  31. data/test/bibtex/test_elements.rb +7 -15
  32. data/test/bibtex/test_entry.rb +78 -87
  33. data/test/bibtex/test_filters.rb +8 -7
  34. data/test/bibtex/test_lexer.rb +10 -13
  35. data/test/bibtex/test_name_parser.rb +6 -9
  36. data/test/bibtex/test_names.rb +50 -55
  37. data/test/bibtex/test_parser.rb +30 -34
  38. data/test/bibtex/test_string.rb +8 -9
  39. data/test/bibtex/test_utilities.rb +6 -9
  40. data/test/bibtex/test_value.rb +41 -43
  41. data/test/helper.rb +3 -6
  42. data/test/macruby.rb +12 -13
  43. data/test/profile.rb +16 -16
  44. data/test/test_bibtex.rb +10 -15
  45. data/test/test_export.rb +5 -13
  46. metadata +4 -4
@@ -1,8 +1,7 @@
1
- # coding: utf-8
2
-
3
1
  module BibTeX
4
2
  begin
5
- original_verbosity, $VERBOSE = $VERBOSE, nil
3
+ original_verbosity = $VERBOSE
4
+ $VERBOSE = nil
6
5
 
7
6
  require 'iconv'
8
7
 
@@ -12,8 +11,7 @@ module BibTeX
12
11
  @iconv.iconv(str)
13
12
  end
14
13
  rescue LoadError
15
-
16
- @iconv_replacements = Hash[*%w(ä ae ö oe ü ue Ä Ae Ö Oe Ü Ue ß ss)]
14
+ @iconv_replacements = Hash['ä', 'ae', 'ö', 'oe', 'ü', 'ue', 'Ä', 'Ae', 'Ö', 'Oe', 'Ü', 'Ue', 'ß', 'ss']
17
15
 
18
16
  # Returns +str+ transliterated containing only ASCII characters.
19
17
  def self.transliterate(str)
@@ -17,7 +17,6 @@
17
17
  #++
18
18
 
19
19
  module BibTeX
20
-
21
20
  #
22
21
  # The base class for BibTeX objects.
23
22
  #
@@ -35,7 +34,7 @@ module BibTeX
35
34
  when Hash
36
35
  [Entry.new(input)]
37
36
  when Array
38
- input.inject([]) { |s,a| s.concat(parse(a, options)) }
37
+ input.inject([]) { |s, a| s.concat(parse(a, options)) }
39
38
  when ::String
40
39
  Parser.new(options).parse(input).data.each do |e|
41
40
  e.parse_names unless !e.respond_to?(:parse_names) || options[:parse_names] == false
@@ -47,31 +46,37 @@ module BibTeX
47
46
  end
48
47
 
49
48
  # Returns a string containing the object's content.
50
- def content(options = {})
49
+ def content(_options = {})
51
50
  ''
52
51
  end
53
52
 
54
53
  # Returns a string containing the object's content.
55
- def values_at(*arguments)
54
+ def values_at(*_arguments)
56
55
  []
57
56
  end
58
57
 
59
- def digest(*arguments)
58
+ def digest(*_arguments)
60
59
  [type, content].join('|')
61
60
  end
62
61
 
63
62
  # Invokes BibTeX string replacement on this element.
64
- def replace(*arguments); self; end
63
+ def replace(*_arguments)
64
+ self
65
+ end
65
66
 
66
67
  # Invokes BibTeX string joining on this element.
67
- def join; self; end
68
+ def join
69
+ self
70
+ end
68
71
 
69
72
  # Returns the element's id.
70
- def id; @id ||= object_id.to_s; end
73
+ def id
74
+ @id ||= object_id.to_s
75
+ end
71
76
 
72
77
  # Returns the BibTeX type (if applicable) or the normalized class name.
73
78
  def type
74
- self.class.name.split(/::/).last.gsub(/([[:lower:]])([[:upper:]])/) { "#{$1}_#{$2}" }.downcase.intern
79
+ self.class.name.split(/::/).last.gsub(/([[:lower:]])([[:upper:]])/) { "#{Regexp.last_match(1)}_#{Regexp.last_match(2)}" }.downcase.intern
75
80
  end
76
81
 
77
82
  # Returns a list of names for that Element. All Elements except Entries return an empty list.
@@ -83,7 +88,7 @@ module BibTeX
83
88
  self.type == type.intern || defined?(type) == 'constant' && is_a?(type)
84
89
  end
85
90
 
86
- [:entry, :book, :article, :collection, :string, :preamble, :comment].each do |type|
91
+ %i[entry book article collection string preamble comment].each do |type|
87
92
  method_id = "#{type}?"
88
93
  define_method(method_id) { has_type?(type) } unless method_defined?(method_id)
89
94
  end
@@ -99,11 +104,11 @@ module BibTeX
99
104
  query == self
100
105
  when Regexp
101
106
  to_s.match(query)
102
- when /^\/(.+)\/$/
103
- to_s.match(Regexp.new($1))
107
+ when %r{^/(.+)/$}
108
+ to_s.match(Regexp.new(Regexp.last_match(1)))
104
109
  when /@(\*|\w+)(?:\[([^\]]*)\])?/
105
110
  query.scan(/(!)?@(\*|\w+)(?:\[([^\]]*)\])?/).any? do |non, type, condition|
106
- if (non ? !has_type?(type) : has_type?(type))
111
+ if non ? !has_type?(type) : has_type?(type)
107
112
  if condition.nil? || condition.empty?
108
113
  true
109
114
  else
@@ -141,11 +146,11 @@ module BibTeX
141
146
 
142
147
  alias to_s content
143
148
 
144
- def to_hash(options = {})
149
+ def to_hash(_options = {})
145
150
  { type => content }
146
151
  end
147
152
 
148
- def to_yaml(options = {})
153
+ def to_yaml(_options = {})
149
154
  require 'yaml'
150
155
  to_hash.to_yaml
151
156
  end
@@ -158,7 +163,7 @@ module BibTeX
158
163
  ::JSON.dump(to_hash(options))
159
164
  end
160
165
 
161
- def to_xml(options = {})
166
+ def to_xml(_options = {})
162
167
  require 'rexml/document'
163
168
  xml = REXML::Element.new(type)
164
169
  xml.text = content
@@ -173,13 +178,14 @@ module BibTeX
173
178
  end
174
179
 
175
180
  # Called when the element was removed from a bibliography.
176
- def removed_from_bibliography(bibliography)
181
+ def removed_from_bibliography(_bibliography)
177
182
  @bibliography = nil
178
183
  self
179
184
  end
180
185
 
181
186
  def <=>(other)
182
- return nil unless other.respond_to? :type and other.respond_to? :to_s
187
+ return nil unless other.respond_to?(:type) && other.respond_to?(:to_s)
188
+
183
189
  [type, to_s] <=> [other.type, other.to_s]
184
190
  end
185
191
 
@@ -191,26 +197,26 @@ module BibTeX
191
197
  private
192
198
 
193
199
  def meets_condition?(condition)
194
- property, operator, value = condition.split(/\s*([!~\/\^<>]?=|!~)\s*/)
200
+ property, operator, value = condition.split(%r{\s*([!~/\^<>]?=|!~)\s*})
195
201
 
196
202
  if property.nil?
197
203
  true
198
204
  else
199
205
  property.strip!
200
- value.strip! unless value.nil?
206
+ value&.strip!
201
207
 
202
208
  if operator.nil? && value.nil?
203
209
  respond_to?(:provides?) && provides?(property)
204
210
  else
205
211
 
206
- # Hack: we need to get rid of #type returning the bibtex_type,
212
+ # HACK: we need to get rid of #type returning the bibtex_type,
207
213
  # because type is a valid BibTeX property. This mitigates the
208
214
  # issue but is no fix!
209
- if property == 'type'
210
- actual = respond_to?(:fields) ? fields[:type] : nil
211
- else
212
- actual = respond_to?(property) ? send(property) : nil
213
- end
215
+ actual = if property == 'type'
216
+ respond_to?(:fields) ? fields[:type] : nil
217
+ else
218
+ respond_to?(property) ? send(property) : nil
219
+ end
214
220
 
215
221
  case operator
216
222
  when '!=', '/='
@@ -233,7 +239,6 @@ module BibTeX
233
239
  end
234
240
  end
235
241
 
236
-
237
242
  #
238
243
  # Represents a @string object.
239
244
  #
@@ -251,7 +256,8 @@ module BibTeX
251
256
 
252
257
  # Creates a new instance.
253
258
  def initialize(key = nil, value = nil)
254
- @key, @value = key.to_sym, Value.new(value)
259
+ @key = key.to_sym
260
+ @value = Value.new(value)
255
261
  yield self if block_given?
256
262
  end
257
263
 
@@ -272,7 +278,6 @@ module BibTeX
272
278
  @key == key ? @value : nil
273
279
  end
274
280
 
275
-
276
281
  # Called when the element was added to a bibliography.
277
282
  def added_to_bibliography(bibliography)
278
283
  super
@@ -289,26 +294,27 @@ module BibTeX
289
294
 
290
295
  # Returns a string representation of the @string's content.
291
296
  def content
292
- "#@key = #{@value.to_s(:quotes => '"')}"
297
+ "#{@key} = #{@value.to_s(quotes: '"')}"
293
298
  end
294
299
 
295
300
  # Returns a string representation of the @string object.
296
- def to_s(options = {})
301
+ def to_s(_options = {})
297
302
  "@string{ #{content} }\n"
298
303
  end
299
304
 
300
- def to_hash(options = {})
301
- { :string => { @key => @value.to_s(:quotes => '"') } }
305
+ def to_hash(_options = {})
306
+ { string: { @key => @value.to_s(quotes: '"') } }
302
307
  end
303
308
 
304
- def to_xml(options = {})
309
+ def to_xml(_options = {})
305
310
  require 'rexml/document'
306
311
 
307
312
  xml = REXML::Element.new(:string)
308
313
 
309
- k, v = REXML::Element.new(:key), REXML::Element.new(:value)
314
+ k = REXML::Element.new(:key)
315
+ v = REXML::Element.new(:value)
310
316
  k.text = key.to_s
311
- v.text = value.to_s(:quotes => '"')
317
+ v.text = value.to_s(quotes: '"')
312
318
 
313
319
  xml.add_elements(k)
314
320
  xml.add_elements(v)
@@ -333,11 +339,11 @@ module BibTeX
333
339
 
334
340
  # Returns a string representation of the @preamble's content.
335
341
  def content
336
- @value.to_s(:quotes => '"')
342
+ @value.to_s(quotes: '"')
337
343
  end
338
344
 
339
345
  # Returns a string representation of the @preamble object
340
- def to_s(options = {})
346
+ def to_s(_options = {})
341
347
  "@preamble{ #{content} }\n"
342
348
  end
343
349
  end
@@ -350,8 +356,8 @@ module BibTeX
350
356
  @content = content
351
357
  end
352
358
 
353
- def to_s(options = {})
354
- "@comment{ #@content }\n"
359
+ def to_s(_options = {})
360
+ "@comment{ #{@content} }\n"
355
361
  end
356
362
  end
357
363
 
@@ -370,7 +376,8 @@ module BibTeX
370
376
  @content = content
371
377
  end
372
378
 
373
- def to_s(options = {}); @content; end
379
+ def to_s(_options = {})
380
+ @content
381
+ end
374
382
  end
375
-
376
383
  end
data/lib/bibtex/entry.rb CHANGED
@@ -25,44 +25,43 @@ module BibTeX
25
25
  include Enumerable
26
26
 
27
27
  # Defines the required fields of the standard entry types
28
- REQUIRED_FIELDS = Hash.new([]).merge({
29
- :article => [:author,:title,:journal,:year],
30
- :book => [[:author,:editor],:title,:publisher,:year],
31
- :booklet => [:title],
32
- :conference => [:author,:title,:booktitle,:year],
33
- :inbook => [[:author,:editor],:title,[:chapter,:pages],:publisher,:year],
34
- :incollection => [:author,:title,:booktitle,:publisher,:year],
35
- :inproceedings => [:author,:title,:booktitle,:year],
36
- :manual => [:title],
37
- :mastersthesis => [:author,:title,:school,:year],
38
- :misc => [],
39
- :phdthesis => [:author,:title,:school,:year],
40
- :proceedings => [:title,:year],
41
- :techreport => [:author,:title,:institution,:year],
42
- :unpublished => [:author,:title,:note]
43
- }).freeze
28
+ REQUIRED_FIELDS = Hash.new([]).merge(
29
+ article: %i[author title journal year],
30
+ book: [%i[author editor], :title, :publisher, :year],
31
+ booklet: [:title],
32
+ conference: %i[author title booktitle year],
33
+ inbook: [%i[author editor], :title, %i[chapter pages], :publisher, :year],
34
+ incollection: %i[author title booktitle publisher year],
35
+ inproceedings: %i[author title booktitle year],
36
+ manual: [:title],
37
+ mastersthesis: %i[author title school year],
38
+ misc: [],
39
+ phdthesis: %i[author title school year],
40
+ proceedings: %i[title year],
41
+ techreport: %i[author title institution year],
42
+ unpublished: %i[author title note]
43
+ ).freeze
44
44
 
45
45
  # Defines the default fallbacks for values defined in cross-references
46
46
  FIELD_ALIASES = {
47
- :booktitle => :title,
47
+ booktitle: :title
48
48
  # :editor => :author
49
49
  }.freeze
50
50
 
51
+ NAME_FIELDS = %i[author editor translator director producer composer].freeze
52
+ DATE_FIELDS = %i[year month day date].freeze
51
53
 
52
- NAME_FIELDS = [:author,:editor,:translator,:director,:producer,:composer].freeze
53
- DATE_FIELDS = [:year,:month,:day,:date].freeze
54
+ MONTHS = %i[jan feb mar apr may jun jul aug sep oct nov dec].freeze
54
55
 
55
- MONTHS = [:jan,:feb,:mar,:apr,:may,:jun,:jul,:aug,:sep,:oct,:nov,:dec].freeze
56
-
57
- MONTHS_FILTER = Hash.new do |h,k|
58
- case k.to_s.strip
59
- when /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i
60
- h[k] = Value.new(k.to_s[0,3].downcase.to_sym)
61
- when /^\d\d?$/
62
- h[k] = Value.new(MONTHS[k.to_i - 1] || k)
63
- else
64
- h[k] = Value.new(k)
65
- end
56
+ MONTHS_FILTER = Hash.new do |h, k|
57
+ h[k] = case k.to_s.strip
58
+ when /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i
59
+ Value.new(k.to_s[0, 3].downcase.to_sym)
60
+ when /^\d\d?$/
61
+ Value.new(MONTHS[k.to_i - 1] || k)
62
+ else
63
+ Value.new(k)
64
+ end
66
65
  end
67
66
 
68
67
  attr_reader :fields, :type
@@ -74,8 +73,8 @@ module BibTeX
74
73
  @fields = {}
75
74
  @key = nil
76
75
 
77
- self.type = attributes.delete(:bibtex_type) if attributes.has_key?(:bibtex_type)
78
- self.key = attributes.delete(:bibtex_key) if attributes.has_key?(:bibtex_key)
76
+ self.type = attributes.delete(:bibtex_type) if attributes.key?(:bibtex_type)
77
+ self.key = attributes.delete(:bibtex_key) if attributes.key?(:bibtex_key)
79
78
 
80
79
  add(attributes)
81
80
 
@@ -120,28 +119,36 @@ module BibTeX
120
119
 
121
120
  # Generate accessors for required fields (#52)
122
121
  REQUIRED_FIELDS.values.flatten.uniq.each do |name|
123
- define_method(name) do
124
- get name
125
- end unless method_defined? name
122
+ unless method_defined? name
123
+ define_method(name) do
124
+ get name
125
+ end
126
+ end
126
127
 
127
128
  writer = "#{name}="
128
129
 
130
+ next if method_defined? writer
131
+
129
132
  define_method(writer) do |value|
130
133
  add name, value
131
- end unless method_defined? writer
134
+ end
132
135
  end
133
136
 
134
137
  # Generate author, editor and translator accessors
135
138
  NAME_FIELDS.each do |contributor|
136
- define_method(contributor) do
137
- get contributor
138
- end unless method_defined? contributor
139
+ unless method_defined? contributor
140
+ define_method(contributor) do
141
+ get contributor
142
+ end
143
+ end
139
144
 
140
145
  writer = "#{contributor}="
141
146
 
142
- define_method(writer) do |value|
143
- add contributor, value
144
- end unless method_defined? writer
147
+ unless method_defined? writer
148
+ define_method(writer) do |value|
149
+ add contributor, value
150
+ end
151
+ end
145
152
 
146
153
  alias_method "#{contributor}s", contributor
147
154
  alias_method "#{contributor}s=", writer
@@ -168,7 +175,6 @@ module BibTeX
168
175
 
169
176
  alias each_pair each
170
177
 
171
-
172
178
  # Returns the Entry's field name aliases.
173
179
  def aliases
174
180
  @aliases ||= FIELD_ALIASES.dup
@@ -189,7 +195,7 @@ module BibTeX
189
195
  end
190
196
 
191
197
  @key = key
192
- rescue => e
198
+ rescue StandardError => e
193
199
  raise BibTeXError, "failed to set key to #{key.inspect}: #{e.message}"
194
200
  end
195
201
 
@@ -215,10 +221,9 @@ module BibTeX
215
221
 
216
222
  alias type? has_type?
217
223
 
218
-
219
224
  def has_field?(*names)
220
225
  names.flatten.any? do |name|
221
- name.respond_to?(:to_sym) ? fields.has_key?(name.to_sym) : false
226
+ name.respond_to?(:to_sym) ? fields.key?(name.to_sym) : false
222
227
  end
223
228
  end
224
229
 
@@ -250,6 +255,7 @@ module BibTeX
250
255
  # corresponding alias is defined.
251
256
  def provide(name)
252
257
  return nil unless name.respond_to?(:to_sym)
258
+
253
259
  name = name.to_sym
254
260
  fields[name] || fields[aliases[name]]
255
261
  end
@@ -275,13 +281,9 @@ module BibTeX
275
281
  def field_names(filter = [], include_inherited = true)
276
282
  names = fields.keys
277
283
 
278
- if include_inherited && has_parent?
279
- names.concat(inherited_fields)
280
- end
284
+ names.concat(inherited_fields) if include_inherited && has_parent?
281
285
 
282
- unless filter.empty?
283
- names = names & filter.map(&:to_sym)
284
- end
286
+ names &= filter.map(&:to_sym) unless filter.empty?
285
287
 
286
288
  names.sort!
287
289
  names
@@ -292,29 +294,27 @@ module BibTeX
292
294
  return [] unless has_parent?
293
295
 
294
296
  names = parent.fields.keys - fields.keys
295
- names.concat(parent.aliases.reject { |k,v| !parent.has_field?(v) }.keys)
297
+ names.concat(parent.aliases.select { |_k, v| parent.has_field?(v) }.keys)
296
298
  names.sort!
297
299
 
298
300
  names
299
301
  end
300
302
 
301
-
302
303
  def method_missing(name, *args, &block)
303
- case
304
- when fields.has_key?(name)
304
+ if fields.key?(name)
305
305
  fields[name]
306
- when name.to_s =~ /^(.+)=$/
307
- send(:add, $1.to_sym, args[0])
308
- when name =~ /^(?:convert|from)_([a-z]+)(!)?$/
309
- $2 ? convert!($1, &block) : convert($1, &block)
310
- when has_parent? && parent.provides?(name)
306
+ elsif name.to_s =~ /^(.+)=$/
307
+ send(:add, Regexp.last_match(1).to_sym, args[0])
308
+ elsif name =~ /^(?:convert|from)_([a-z]+)(!)?$/
309
+ Regexp.last_match(2) ? convert!(Regexp.last_match(1), &block) : convert(Regexp.last_match(1), &block)
310
+ elsif has_parent? && parent.provides?(name)
311
311
  parent.provide(name)
312
312
  else
313
313
  super
314
314
  end
315
315
  end
316
316
 
317
- def respond_to?(method, include_all=false)
317
+ def respond_to?(method, include_all = false)
318
318
  provides?(method.to_sym) || method.to_s.match(/=$/) ||
319
319
  method =~ /^(?:convert|from)_([a-z]+)(!)?$/ ||
320
320
  (has_parent? && parent.respond_to?(method, include_all)) || super
@@ -328,8 +328,8 @@ module BibTeX
328
328
  # Renames the given field names unless a field with the new name already
329
329
  # exists.
330
330
  def rename!(*arguments)
331
- Hash[*arguments.flatten].each_pair do |from,to|
332
- if fields.has_key?(from) && !fields.has_key?(to)
331
+ Hash[*arguments.flatten].each_pair do |from, to|
332
+ if fields.key?(from) && !fields.key?(to)
333
333
  fields[to] = fields[from]
334
334
  fields.delete(from)
335
335
  end
@@ -344,7 +344,7 @@ module BibTeX
344
344
  # defined and the entry has cross-reference, returns the cross-referenced
345
345
  # value instead.
346
346
  def [](name)
347
- fields[name.to_sym] || parent && parent.provide(name)
347
+ fields[name.to_sym] || parent&.provide(name)
348
348
  end
349
349
 
350
350
  alias get []
@@ -418,12 +418,11 @@ module BibTeX
418
418
  end
419
419
 
420
420
  def identifier
421
- case
422
- when provides?(:doi)
421
+ if provides?(:doi)
423
422
  "info:doi/#{get(:doi)}"
424
- when provides?(:isbn)
423
+ elsif provides?(:isbn)
425
424
  "urn:isbn:#{get(:isbn)}"
426
- when provides?(:issn)
425
+ elsif provides?(:issn)
427
426
  "urn:issn:#{get(:issn)}"
428
427
  else
429
428
  "urn:bibtex:#{key}"
@@ -436,11 +435,11 @@ module BibTeX
436
435
 
437
436
  @key = register(key)
438
437
 
439
- [:parse_names, :parse_months].each do |parser|
438
+ %i[parse_names parse_months].each do |parser|
440
439
  send(parser) if bibliography.options[parser]
441
440
  end
442
441
 
443
- if bibliography.options.has_key?(:filter)
442
+ if bibliography.options.key?(:filter)
444
443
  [*bibliography.options[:filter]].each do |filter|
445
444
  convert!(filter)
446
445
  end
@@ -470,7 +469,7 @@ module BibTeX
470
469
  return nil if bibliography.nil?
471
470
 
472
471
  k = key.dup
473
- k.succ! while bibliography.has_key?(k)
472
+ k.succ! while bibliography.key?(k)
474
473
  bibliography.entries[k] = self
475
474
  k
476
475
  end
@@ -537,7 +536,6 @@ module BibTeX
537
536
  NAME_FIELDS.map { |k| has_field?(k) ? @fields[k].tokens : nil }.flatten.compact
538
537
  end
539
538
 
540
-
541
539
  # Returns true if the Entry has a valid cross-reference in the Bibliography.
542
540
  def has_parent?
543
541
  !parent.nil?
@@ -561,7 +559,6 @@ module BibTeX
561
559
 
562
560
  alias cross_reference parent
563
561
 
564
-
565
562
  # Returns true if the entry is cross-referenced by another entry in the
566
563
  # Bibliography.
567
564
  def has_children?
@@ -574,7 +571,7 @@ module BibTeX
574
571
  # cross-reference to this entry or [] if there are no references to this
575
572
  # entry.
576
573
  def children
577
- bibliography && bibliography.q("@entry[crossref=#{key}]") or []
574
+ bibliography&.q("@entry[crossref=#{key}]") || []
578
575
  end
579
576
 
580
577
  alias cross_referenced_by children
@@ -618,7 +615,7 @@ module BibTeX
618
615
  filters = filters.flatten.map { |f| Filters.resolve!(f) }
619
616
 
620
617
  fields.each_pair do |k, v|
621
- (!block_given? || yield(k, v)) ? v.convert!(*filters) : v
618
+ !block_given? || yield(k, v) ? v.convert!(*filters) : v
622
619
  end
623
620
 
624
621
  self
@@ -628,22 +625,21 @@ module BibTeX
628
625
  type != other.type ? type <=> other.type : key != other.key ? key <=> other.key : to_s <=> other.to_s
629
626
  end
630
627
 
631
-
632
628
  # Returns a string of all the entry's fields.
633
629
  def content(options = {})
634
- fields.map { |k,v| "#{k} = #{ fields[k].to_s(options) }" }.join(",\n")
630
+ fields.map { |k, _v| "#{k} = #{fields[k].to_s(options)}" }.join(",\n")
635
631
  end
636
632
 
637
633
  # Returns a string representation of the entry.
638
634
  def to_s(options = {})
639
- options[:quotes] ||= %w({ })
640
- ["@#{type}{#{key},", content(options).gsub(/^/,' '), "}\n"].join("\n")
635
+ options[:quotes] ||= %w[{ }]
636
+ ["@#{type}{#{key},", content(options).gsub(/^/, ' '), "}\n"].join("\n")
641
637
  end
642
638
 
643
639
  def to_hash(options = {})
644
- options[:quotes] ||= %w({ })
645
- hash = { :bibtex_key => key, :bibtex_type => type }
646
- each_pair { |k,v| hash[k] = v.to_s(options) }
640
+ options[:quotes] ||= %w[{ }]
641
+ hash = { bibtex_key: key, bibtex_type: type }
642
+ each_pair { |k, v| hash[k] = v.to_s(options) }
647
643
  hash
648
644
  end
649
645
 
@@ -656,7 +652,7 @@ module BibTeX
656
652
  end
657
653
 
658
654
  # Returns a RDF::Graph representation of the entry using the BIBO ontology.
659
- def to_rdf(options = {})
655
+ def to_rdf(_options = {})
660
656
  if defined?(::RDF)
661
657
  RDFConverter.convert(self)
662
658
  else