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.
- checksums.yaml +4 -4
- data/Gemfile +23 -24
- data/History.txt +4 -0
- data/Rakefile +23 -25
- data/bibtex-ruby.gemspec +1 -1
- data/examples/bib2html.rb +5 -6
- data/examples/bib2yaml.rb +2 -2
- data/features/step_definitions/bibtex_steps.rb +3 -6
- data/features/step_definitions/name_steps.rb +1 -2
- data/lib/bibtex.rb +11 -13
- data/lib/bibtex/bibliography.rb +45 -58
- data/lib/bibtex/compatibility.rb +3 -5
- data/lib/bibtex/elements.rb +49 -42
- data/lib/bibtex/entry.rb +80 -84
- data/lib/bibtex/entry/citeproc_converter.rb +47 -52
- data/lib/bibtex/entry/rdf_converter.rb +97 -63
- data/lib/bibtex/error.rb +10 -11
- data/lib/bibtex/extensions.rb +2 -5
- data/lib/bibtex/filters.rb +4 -9
- data/lib/bibtex/filters/latex.rb +0 -2
- data/lib/bibtex/filters/linebreaks.rb +0 -2
- data/lib/bibtex/lexer.rb +81 -81
- data/lib/bibtex/names.rb +24 -28
- data/lib/bibtex/replaceable.rb +15 -17
- data/lib/bibtex/utilities.rb +5 -10
- data/lib/bibtex/value.rb +28 -34
- data/lib/bibtex/version.rb +6 -6
- data/test/benchmark.rb +20 -22
- data/test/bibtex/entry/test_rdf_converter.rb +3 -5
- data/test/bibtex/test_bibliography.rb +22 -35
- data/test/bibtex/test_elements.rb +7 -15
- data/test/bibtex/test_entry.rb +78 -87
- data/test/bibtex/test_filters.rb +8 -7
- data/test/bibtex/test_lexer.rb +10 -13
- data/test/bibtex/test_name_parser.rb +6 -9
- data/test/bibtex/test_names.rb +50 -55
- data/test/bibtex/test_parser.rb +30 -34
- data/test/bibtex/test_string.rb +8 -9
- data/test/bibtex/test_utilities.rb +6 -9
- data/test/bibtex/test_value.rb +41 -43
- data/test/helper.rb +3 -6
- data/test/macruby.rb +12 -13
- data/test/profile.rb +16 -16
- data/test/test_bibtex.rb +10 -15
- data/test/test_export.rb +5 -13
- metadata +4 -4
data/lib/bibtex/compatibility.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
module BibTeX
|
4
2
|
begin
|
5
|
-
original_verbosity
|
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)
|
data/lib/bibtex/elements.rb
CHANGED
@@ -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(
|
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(*
|
54
|
+
def values_at(*_arguments)
|
56
55
|
[]
|
57
56
|
end
|
58
57
|
|
59
|
-
def digest(*
|
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(*
|
63
|
+
def replace(*_arguments)
|
64
|
+
self
|
65
|
+
end
|
65
66
|
|
66
67
|
# Invokes BibTeX string joining on this element.
|
67
|
-
def join
|
68
|
+
def join
|
69
|
+
self
|
70
|
+
end
|
68
71
|
|
69
72
|
# Returns the element's id.
|
70
|
-
def id
|
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:]])/) { "#{
|
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
|
-
[
|
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(
|
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
|
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(
|
149
|
+
def to_hash(_options = {})
|
145
150
|
{ type => content }
|
146
151
|
end
|
147
152
|
|
148
|
-
def to_yaml(
|
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(
|
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(
|
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?
|
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(
|
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
|
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
|
-
#
|
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
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
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
|
-
"
|
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(
|
301
|
+
def to_s(_options = {})
|
297
302
|
"@string{ #{content} }\n"
|
298
303
|
end
|
299
304
|
|
300
|
-
def to_hash(
|
301
|
-
{ :
|
305
|
+
def to_hash(_options = {})
|
306
|
+
{ string: { @key => @value.to_s(quotes: '"') } }
|
302
307
|
end
|
303
308
|
|
304
|
-
def to_xml(
|
309
|
+
def to_xml(_options = {})
|
305
310
|
require 'rexml/document'
|
306
311
|
|
307
312
|
xml = REXML::Element.new(:string)
|
308
313
|
|
309
|
-
k
|
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(:
|
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(:
|
342
|
+
@value.to_s(quotes: '"')
|
337
343
|
end
|
338
344
|
|
339
345
|
# Returns a string representation of the @preamble object
|
340
|
-
def to_s(
|
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(
|
354
|
-
"@comment{
|
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(
|
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
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
|
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
|
-
:
|
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
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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.
|
78
|
-
self.key = attributes.delete(:bibtex_key) if attributes.
|
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
|
-
|
124
|
-
|
125
|
-
|
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
|
134
|
+
end
|
132
135
|
end
|
133
136
|
|
134
137
|
# Generate author, editor and translator accessors
|
135
138
|
NAME_FIELDS.each do |contributor|
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
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.
|
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.
|
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
|
-
|
304
|
-
when fields.has_key?(name)
|
304
|
+
if fields.key?(name)
|
305
305
|
fields[name]
|
306
|
-
|
307
|
-
send(:add,
|
308
|
-
|
309
|
-
|
310
|
-
|
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.
|
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
|
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
|
-
|
422
|
-
when provides?(:doi)
|
421
|
+
if provides?(:doi)
|
423
422
|
"info:doi/#{get(:doi)}"
|
424
|
-
|
423
|
+
elsif provides?(:isbn)
|
425
424
|
"urn:isbn:#{get(:isbn)}"
|
426
|
-
|
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
|
-
[
|
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.
|
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.
|
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
|
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
|
-
|
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,
|
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 = { :
|
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(
|
655
|
+
def to_rdf(_options = {})
|
660
656
|
if defined?(::RDF)
|
661
657
|
RDFConverter.convert(self)
|
662
658
|
else
|