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/replaceable.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# BibTeX-Ruby
|
3
|
-
# Copyright (C) 2010
|
3
|
+
# Copyright (C) 2010 Sylvester Keil <sylvester.keil.or.at>
|
4
4
|
#
|
5
5
|
# This program is free software: you can redistribute it and/or modify
|
6
6
|
# it under the terms of the GNU General Public License as published by
|
@@ -9,15 +9,14 @@
|
|
9
9
|
#
|
10
10
|
# This program is distributed in the hope that it will be useful,
|
11
11
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
13
|
# GNU General Public License for more details.
|
14
14
|
#
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
|
-
# along with this program.
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
#++
|
18
18
|
|
19
19
|
module BibTeX
|
20
|
-
|
21
20
|
#
|
22
21
|
# The Replaceable module provides methods that expose a Value attribute
|
23
22
|
# and the ability to join or replace the contained BibTeX symbols.
|
@@ -27,26 +26,25 @@ module BibTeX
|
|
27
26
|
|
28
27
|
attr_reader :value
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def value=(value)
|
30
|
+
@value = Value.new(value)
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def replace(*arguments)
|
34
|
+
@value.replace(*arguments)
|
35
|
+
self
|
36
|
+
end
|
38
37
|
|
39
38
|
def join
|
40
39
|
@value.join
|
41
40
|
self
|
42
41
|
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
alias :v :value
|
43
|
+
def <<(value)
|
44
|
+
@value << value
|
45
|
+
self
|
46
|
+
end
|
50
47
|
|
48
|
+
alias v value
|
51
49
|
end
|
52
50
|
end
|
data/lib/bibtex/utilities.rb
CHANGED
@@ -17,9 +17,7 @@
|
|
17
17
|
#++
|
18
18
|
|
19
19
|
module BibTeX
|
20
|
-
|
21
20
|
class << self
|
22
|
-
|
23
21
|
# Opens a BibTeX file or URI and returns a corresponding +Bibliography+
|
24
22
|
# object or, if a block is given, yields the Bibliography to the block,
|
25
23
|
# ensuring that the file is saved.
|
@@ -30,10 +28,9 @@ module BibTeX
|
|
30
28
|
# Parses the given string and returns a corresponding +Bibliography+ object.
|
31
29
|
# Delegates to BibTeX.open if the string is a filename or URI.
|
32
30
|
def parse(string, options = {}, &block)
|
33
|
-
|
34
|
-
when string.length < 260 && File.exist?(string)
|
31
|
+
if string.length < 260 && File.exist?(string)
|
35
32
|
Bibliography.open(string, options, &block)
|
36
|
-
|
33
|
+
elsif string =~ %r{\A[a-z]+://}i
|
37
34
|
Bibliography.open(string, options)
|
38
35
|
else
|
39
36
|
Bibliography.parse(string, options)
|
@@ -50,10 +47,8 @@ module BibTeX
|
|
50
47
|
Names.parse(string)
|
51
48
|
end
|
52
49
|
|
53
|
-
alias
|
54
|
-
alias
|
55
|
-
alias
|
56
|
-
|
50
|
+
alias name names
|
51
|
+
alias parse_name names
|
52
|
+
alias parse_names names
|
57
53
|
end
|
58
|
-
|
59
54
|
end
|
data/lib/bibtex/value.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
#--
|
4
2
|
# BibTeX-Ruby
|
5
3
|
# Copyright (C) 2010-2015 Sylvester Keil <sylvester.keil.or.at>
|
@@ -21,8 +19,6 @@
|
|
21
19
|
require 'forwardable'
|
22
20
|
|
23
21
|
module BibTeX
|
24
|
-
|
25
|
-
|
26
22
|
# A BibTeX Value is something very much like a string. In BibTeX files it
|
27
23
|
# can appear on the right hand side of @string or @entry field assignments
|
28
24
|
# or as @preamble contents. In the example below [VALUE] indicates possible
|
@@ -53,9 +49,9 @@ module BibTeX
|
|
53
49
|
alias to_a tokens
|
54
50
|
|
55
51
|
def_delegators :to_s, :=~, :===,
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
*String.instance_methods(false).reject do |m|
|
53
|
+
m =~ /^\W|^(length|dup|replace|to_s|inspect)$|!$/
|
54
|
+
end
|
59
55
|
|
60
56
|
def_delegators :@tokens, :[], :length
|
61
57
|
def_delegator :@tokens, :each, :each_token
|
@@ -79,9 +75,8 @@ module BibTeX
|
|
79
75
|
|
80
76
|
def initialize_copy(other)
|
81
77
|
@tokens = other.tokens.map do |token|
|
82
|
-
|
83
|
-
|
84
|
-
when token.is_a?(Symbol) then token
|
78
|
+
if token.nil? then nil
|
79
|
+
elsif token.is_a?(Symbol) then token
|
85
80
|
else token.dup
|
86
81
|
end
|
87
82
|
end
|
@@ -115,7 +110,7 @@ module BibTeX
|
|
115
110
|
if argument.respond_to?(:to_s)
|
116
111
|
@tokens << argument.to_s
|
117
112
|
else
|
118
|
-
raise(ArgumentError, "Failed to create Value from argument #{
|
113
|
+
raise(ArgumentError, "Failed to create Value from argument #{argument.inspect}; expected String, Symbol or Value instance.")
|
119
114
|
end
|
120
115
|
end
|
121
116
|
self
|
@@ -124,10 +119,10 @@ module BibTeX
|
|
124
119
|
alias << add
|
125
120
|
alias push add
|
126
121
|
|
127
|
-
[
|
122
|
+
%i[strip! upcase! downcase! sub! gsub! chop! chomp! rstrip!].each do |method_id|
|
128
123
|
define_method(method_id) do |*arguments, &block|
|
129
124
|
@tokens.each do |part|
|
130
|
-
part
|
125
|
+
part&.send(method_id, *arguments, &block)
|
131
126
|
end
|
132
127
|
self
|
133
128
|
end
|
@@ -135,6 +130,7 @@ module BibTeX
|
|
135
130
|
|
136
131
|
def replace(*arguments)
|
137
132
|
return self unless has_symbol?
|
133
|
+
|
138
134
|
arguments.flatten.each do |argument|
|
139
135
|
case argument
|
140
136
|
when ::String # simulates Ruby's String#replace
|
@@ -148,7 +144,6 @@ module BibTeX
|
|
148
144
|
self
|
149
145
|
end
|
150
146
|
|
151
|
-
|
152
147
|
# call-seq:
|
153
148
|
# Value.new('foo', 'bar').join #=> <'foobar'>
|
154
149
|
# Value.new(:foo, 'bar').join #=> <:foo, 'bar'>
|
@@ -157,13 +152,12 @@ module BibTeX
|
|
157
152
|
#
|
158
153
|
# @return {Value} the instance with all consecutive String tokens joined
|
159
154
|
def join(separator = '')
|
160
|
-
@tokens = @tokens.
|
155
|
+
@tokens = @tokens.each_with_object([]) do |b, a|
|
161
156
|
if a[-1].is_a?(::String) && b.is_a?(::String)
|
162
157
|
a[-1] = [a[-1], b].join(separator)
|
163
158
|
else
|
164
159
|
a << b
|
165
160
|
end
|
166
|
-
a
|
167
161
|
end
|
168
162
|
self
|
169
163
|
end
|
@@ -186,8 +180,9 @@ module BibTeX
|
|
186
180
|
# If the option :filter is given, the Value will be converted using
|
187
181
|
# the filter(s) specified.
|
188
182
|
def to_s(options = {})
|
189
|
-
return convert(options.delete(:filter)).to_s(options) if options.
|
190
|
-
return value.to_s unless options.
|
183
|
+
return convert(options.delete(:filter)).to_s(options) if options.key?(:filter)
|
184
|
+
return value.to_s unless options.key?(:quotes) && atomic? && !symbol?
|
185
|
+
|
191
186
|
q = Array(options[:quotes])
|
192
187
|
[q[0], value, q[-1]].compact.join
|
193
188
|
end
|
@@ -200,11 +195,11 @@ module BibTeX
|
|
200
195
|
if atomic?
|
201
196
|
@tokens[0]
|
202
197
|
else
|
203
|
-
@tokens.map { |v|
|
198
|
+
@tokens.map { |v| v.is_a?(::String) ? v.inspect : v }.join(' # ')
|
204
199
|
end
|
205
200
|
end
|
206
201
|
|
207
|
-
alias
|
202
|
+
alias v value
|
208
203
|
|
209
204
|
def inspect
|
210
205
|
"#<#{self.class} #{@tokens.map(&:inspect).join(', ')}>"
|
@@ -216,9 +211,11 @@ module BibTeX
|
|
216
211
|
end
|
217
212
|
|
218
213
|
# Returns true if the value is a BibTeX name value.
|
219
|
-
def name
|
214
|
+
def name?
|
215
|
+
false
|
216
|
+
end
|
220
217
|
|
221
|
-
alias
|
218
|
+
alias names? name?
|
222
219
|
|
223
220
|
def to_name
|
224
221
|
Names.parse(to_s)
|
@@ -235,7 +232,7 @@ module BibTeX
|
|
235
232
|
def to_date
|
236
233
|
require 'date'
|
237
234
|
Date.parse(to_s)
|
238
|
-
rescue
|
235
|
+
rescue StandardError
|
239
236
|
nil
|
240
237
|
end
|
241
238
|
|
@@ -248,7 +245,7 @@ module BibTeX
|
|
248
245
|
@tokens[0].to_i
|
249
246
|
end
|
250
247
|
|
251
|
-
def to_citeproc
|
248
|
+
def to_citeproc(options = {})
|
252
249
|
to_s(options)
|
253
250
|
end
|
254
251
|
|
@@ -265,12 +262,12 @@ module BibTeX
|
|
265
262
|
end
|
266
263
|
|
267
264
|
# Returns a new Value with all string values converted according to the given filter(s).
|
268
|
-
def convert
|
265
|
+
def convert(*filters)
|
269
266
|
dup.convert!(*filters)
|
270
267
|
end
|
271
268
|
|
272
269
|
# Converts all string values according to the given filter(s).
|
273
|
-
def convert!
|
270
|
+
def convert!(*filters)
|
274
271
|
filters.flatten.each do |filter|
|
275
272
|
f = Filters.resolve!(filter)
|
276
273
|
@tokens.map! { |t| f.apply(t) }
|
@@ -279,27 +276,24 @@ module BibTeX
|
|
279
276
|
self
|
280
277
|
end
|
281
278
|
|
282
|
-
def method_missing
|
283
|
-
|
284
|
-
|
285
|
-
$2 ? convert!($1) : convert($1)
|
279
|
+
def method_missing(name, *args)
|
280
|
+
if name.to_s =~ /^(?:convert|from)_([a-z]+)(!)?$/
|
281
|
+
Regexp.last_match(2) ? convert!(Regexp.last_match(1)) : convert(Regexp.last_match(1))
|
286
282
|
else
|
287
283
|
super
|
288
284
|
end
|
289
285
|
end
|
290
286
|
|
291
|
-
def respond_to?
|
287
|
+
def respond_to?(method, include_all = false)
|
292
288
|
method =~ /^(?:convert|from)_([a-z]+)(!)?$/ || super
|
293
289
|
end
|
294
290
|
|
295
|
-
def <=>
|
291
|
+
def <=>(other)
|
296
292
|
if numeric? && other.respond_to?(:numeric?) && other.numeric?
|
297
293
|
to_i <=> other.to_i
|
298
294
|
else
|
299
295
|
to_s <=> other.to_s
|
300
296
|
end
|
301
297
|
end
|
302
|
-
|
303
298
|
end
|
304
|
-
|
305
299
|
end
|
data/lib/bibtex/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# BibTeX-Ruby
|
3
|
-
# Copyright (C) 2010-2015
|
3
|
+
# Copyright (C) 2010-2015 Sylvester Keil <sylvester.keil.or.at>
|
4
4
|
#
|
5
5
|
# This program is free software: you can redistribute it and/or modify
|
6
6
|
# it under the terms of the GNU General Public License as published by
|
@@ -9,18 +9,18 @@
|
|
9
9
|
#
|
10
10
|
# This program is distributed in the hope that it will be useful,
|
11
11
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
13
|
# GNU General Public License for more details.
|
14
14
|
#
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
|
-
# along with this program.
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
#++
|
18
18
|
|
19
19
|
module BibTeX
|
20
20
|
module Version
|
21
|
-
MAJOR =
|
22
|
-
MINOR =
|
23
|
-
PATCH =
|
21
|
+
MAJOR = 5
|
22
|
+
MINOR = 0
|
23
|
+
PATCH = 0
|
24
24
|
BUILD = nil
|
25
25
|
|
26
26
|
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
|
data/test/benchmark.rb
CHANGED
@@ -7,21 +7,22 @@ require 'bibtex'
|
|
7
7
|
|
8
8
|
# data = File.open(BibTeX::Test.fixtures(:benchmark)).read
|
9
9
|
|
10
|
-
input =
|
11
|
-
@book{pickaxe,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
10
|
+
input = <<~END
|
11
|
+
@book{pickaxe,
|
12
|
+
Address = {Raleigh, North Carolina},
|
13
|
+
Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
|
14
|
+
Date-Added = {2010-08-05 09:54:07 +0200},
|
15
|
+
Date-Modified = {2010-08-05 10:07:01 +0200},
|
16
|
+
Keywords = {ruby},
|
17
|
+
Publisher = {The Pragmatic Bookshelf},
|
18
|
+
Series = {The Facets of Ruby},
|
19
|
+
Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
|
20
|
+
Year = {2009}
|
21
|
+
}
|
22
22
|
END
|
23
23
|
|
24
|
-
n
|
24
|
+
n = 31
|
25
|
+
k = 10
|
25
26
|
lexer = BibTeX::Lexer.new
|
26
27
|
# parser = BibTeX::Parser.new
|
27
28
|
|
@@ -31,26 +32,23 @@ g = []
|
|
31
32
|
# Ruby 1.9.3
|
32
33
|
format = Benchmark.const_defined?(:FMTSTR) ? Benchmark::FMTSTR : Benchmark::FORMAT
|
33
34
|
|
34
|
-
Benchmark.benchmark((
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
f << b.report('%14s:' % "f(#{i})") do
|
35
|
+
Benchmark.benchmark((' ' * 15) + CAPTION, 7, format, format('%14s:', 'sum(f)'), format('%14s:', 'sum(g)')) do |b|
|
36
|
+
1.step(n, k) do |i|
|
37
|
+
f << b.report(format('%14s:', "f(#{i})")) do
|
39
38
|
i.times do
|
40
39
|
lexer.data = input
|
41
40
|
lexer.analyse
|
42
|
-
|
41
|
+
# BibTeX::Parser.new.parse(input)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
45
|
data = input * i
|
47
46
|
|
48
|
-
g << b.report('%14s:'
|
47
|
+
g << b.report(format('%14s:', "g(#{i})")) do
|
49
48
|
lexer.data = data
|
50
49
|
lexer.analyse
|
51
|
-
|
50
|
+
# BibTeX::Parser.new.parse(data)
|
52
51
|
end
|
53
|
-
|
54
52
|
end
|
55
53
|
|
56
54
|
[f.inject(:+), g.inject(:+)]
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
require 'helper.rb'
|
4
2
|
|
5
3
|
module BibTeX
|
@@ -37,7 +35,7 @@ module BibTeX
|
|
37
35
|
end
|
38
36
|
|
39
37
|
describe '#bdsk_url' do
|
40
|
-
let(:entry) { Entry.new(
|
38
|
+
let(:entry) { Entry.new('bdsk-url-1': 'http://www.example.com') }
|
41
39
|
|
42
40
|
it 'should run successfully' do
|
43
41
|
subject.bdsk_url
|
@@ -73,7 +71,7 @@ module BibTeX
|
|
73
71
|
end
|
74
72
|
|
75
73
|
describe '#date_added' do
|
76
|
-
let(:entry) { Entry.new(
|
74
|
+
let(:entry) { Entry.new('date-added': '2014-01-20') }
|
77
75
|
|
78
76
|
it 'should run successfully' do
|
79
77
|
subject.date_added
|
@@ -81,7 +79,7 @@ module BibTeX
|
|
81
79
|
end
|
82
80
|
|
83
81
|
describe '#date_modified' do
|
84
|
-
let(:entry) { Entry.new(
|
82
|
+
let(:entry) { Entry.new('date-modified': '2014-01-20') }
|
85
83
|
|
86
84
|
it 'should run successfully' do
|
87
85
|
subject.date_modified
|
@@ -1,11 +1,7 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
1
|
require 'helper'
|
4
2
|
|
5
3
|
module BibTeX
|
6
|
-
|
7
4
|
class BibliographyTest < Minitest::Spec
|
8
|
-
|
9
5
|
describe 'when newly created' do
|
10
6
|
it 'should not be nil' do
|
11
7
|
assert Bibliography.new
|
@@ -27,16 +23,15 @@ module BibTeX
|
|
27
23
|
|
28
24
|
assert_equal b.length - 1, BibTeX.open(tmp.path).length
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
32
27
|
|
33
28
|
describe '.parse' do
|
34
29
|
it 'accepts filters' do
|
35
|
-
Bibliography.parse("@misc{k, title = {\\''u}}", :
|
30
|
+
Bibliography.parse("@misc{k, title = {\\''u}}", filter: 'latex')[0].title.must_be :==, 'ü'
|
36
31
|
end
|
37
32
|
|
38
33
|
it 'accepts filters in an array' do
|
39
|
-
Bibliography.parse("@misc{k, title = {\\''u}}", :
|
34
|
+
Bibliography.parse("@misc{k, title = {\\''u}}", filter: ['latex'])[0].title.must_be :==, 'ü'
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
@@ -89,15 +84,15 @@ module BibTeX
|
|
89
84
|
describe '#extend_initials' do
|
90
85
|
it 'extends the initials in matching names' do
|
91
86
|
@bib.names.map(&:to_s).wont_include 'Flanagan, Dave'
|
92
|
-
@bib.extend_initials([
|
87
|
+
@bib.extend_initials(%w[Dave Flanagan])
|
93
88
|
@bib.names.map(&:to_s).must_include 'Flanagan, Dave'
|
94
89
|
end
|
95
90
|
end
|
96
91
|
|
97
92
|
describe '#extend_initials!' do
|
98
93
|
it 'extends the initials of all names to the longest prototype' do
|
99
|
-
assert_equal
|
100
|
-
|
94
|
+
assert_equal 'Ruby, Sam Thomas, Dave Hansson Heinemeier, David Flanagan, David Matsumoto, Yukihiro Segaran, Thomas',
|
95
|
+
@bib.extend_initials!.names.map(&:sort_order).uniq.join(' ')
|
101
96
|
end
|
102
97
|
end
|
103
98
|
|
@@ -116,7 +111,7 @@ module BibTeX
|
|
116
111
|
it 'passes each entry with matching fields to the block if given' do
|
117
112
|
years = []
|
118
113
|
@bib.unify(:publisher, /reilly/i) { |e| years << e.year.to_s }
|
119
|
-
assert_equal [
|
114
|
+
assert_equal %w[2007 2008], years.sort
|
120
115
|
end
|
121
116
|
|
122
117
|
it 'returns the bibliography' do
|
@@ -144,11 +139,11 @@ module BibTeX
|
|
144
139
|
end
|
145
140
|
|
146
141
|
it 'supports access by range' do
|
147
|
-
assert_equal %w
|
142
|
+
assert_equal %w[2008 2007], @bib[1..2].map(&:year)
|
148
143
|
end
|
149
144
|
|
150
145
|
it 'supports access by index and offset' do
|
151
|
-
assert_equal %w
|
146
|
+
assert_equal %w[2008 2007], @bib[1, 2].map(&:year)
|
152
147
|
end
|
153
148
|
|
154
149
|
it 'supports queries by symbol key' do
|
@@ -192,7 +187,6 @@ module BibTeX
|
|
192
187
|
assert_nil @bib.q(:first, '@collection')
|
193
188
|
end
|
194
189
|
|
195
|
-
|
196
190
|
it 'supports queries by pattern' do
|
197
191
|
assert_equal 0, @bib[/reilly/].length
|
198
192
|
assert_equal 2, @bib[/reilly/i].length
|
@@ -230,7 +224,6 @@ module BibTeX
|
|
230
224
|
assert_equal 0, @bib['@*[year>=2010]'].length
|
231
225
|
end
|
232
226
|
|
233
|
-
|
234
227
|
it 'supports queries by bibtex element' do
|
235
228
|
entry = Entry.parse(<<-END).first
|
236
229
|
@article{segaran2007,
|
@@ -258,7 +251,6 @@ module BibTeX
|
|
258
251
|
end
|
259
252
|
|
260
253
|
describe '#query' do
|
261
|
-
|
262
254
|
it 'returns all elements when passed no arguments' do
|
263
255
|
@bib.query.length.must_be :==, 6
|
264
256
|
end
|
@@ -270,11 +262,9 @@ module BibTeX
|
|
270
262
|
it 'returns all entries when passed a * wildcard' do
|
271
263
|
@bib.query('@*').length.must_be :==, 5
|
272
264
|
end
|
273
|
-
|
274
265
|
end
|
275
266
|
|
276
267
|
describe 'duplicates' do
|
277
|
-
|
278
268
|
it 'understands select_duplicates_by' do
|
279
269
|
assert_equal 1, @bib.select_duplicates_by.length
|
280
270
|
end
|
@@ -282,7 +272,6 @@ module BibTeX
|
|
282
272
|
it 'understands duplicates?' do
|
283
273
|
assert @bib.duplicates?
|
284
274
|
end
|
285
|
-
|
286
275
|
end
|
287
276
|
|
288
277
|
describe '#uniq!' do
|
@@ -320,7 +309,7 @@ module BibTeX
|
|
320
309
|
|
321
310
|
describe 'with block' do
|
322
311
|
it 'removes duplicate entries and returns the bibliography' do
|
323
|
-
assert @a.length > @a.uniq!(:author){|d,e| d+'|'+e.pages_from}.length
|
312
|
+
assert @a.length > @a.uniq!(:author) { |d, e| d + '|' + e.pages_from }.length
|
324
313
|
end
|
325
314
|
end
|
326
315
|
end
|
@@ -328,7 +317,9 @@ module BibTeX
|
|
328
317
|
describe 'given a filter' do
|
329
318
|
before do
|
330
319
|
@filter = Object.new
|
331
|
-
def @filter.apply
|
320
|
+
def @filter.apply(value)
|
321
|
+
value.is_a?(::String) ? value.upcase : value
|
322
|
+
end
|
332
323
|
end
|
333
324
|
|
334
325
|
it 'supports arbitrary conversions' do
|
@@ -341,11 +332,9 @@ module BibTeX
|
|
341
332
|
assert_equal 'ruby, rails', @bib[:rails].keywords
|
342
333
|
assert_equal 'RUBY', @bib[:flanagan2008].keywords
|
343
334
|
end
|
344
|
-
|
345
335
|
end
|
346
336
|
|
347
337
|
describe 'sorting' do
|
348
|
-
|
349
338
|
before do
|
350
339
|
@small_bib = BibTeX.parse <<-END
|
351
340
|
@book{flanagan2008,
|
@@ -372,29 +361,29 @@ module BibTeX
|
|
372
361
|
year={2007},
|
373
362
|
publisher={O'Reilly}
|
374
363
|
}
|
375
|
-
|
376
|
-
|
364
|
+
END
|
365
|
+
end
|
377
366
|
|
378
367
|
it 'can be sorted destructively' do
|
379
368
|
@small_bib.sort!
|
380
|
-
@small_bib.map(&:key).must_equal [
|
369
|
+
@small_bib.map(&:key).must_equal %w[segaran2007 flanagan2008 rails]
|
381
370
|
end
|
382
371
|
|
383
372
|
it 'can be sorted by field destructively' do
|
384
373
|
@small_bib.sort_by! { |e| -e[:year].to_i }
|
385
|
-
@small_bib.map(&:key).must_equal [
|
374
|
+
@small_bib.map(&:key).must_equal %w[rails flanagan2008 segaran2007]
|
386
375
|
end
|
387
376
|
|
388
377
|
it 'can be sorted non-destructively' do
|
389
378
|
sorted_entries = @small_bib.sort
|
390
|
-
sorted_entries.map(&:key).must_equal [
|
391
|
-
@small_bib.map(&:key).must_equal [
|
379
|
+
sorted_entries.map(&:key).must_equal %w[segaran2007 flanagan2008 rails]
|
380
|
+
@small_bib.map(&:key).must_equal %w[flanagan2008 rails segaran2007]
|
392
381
|
end
|
393
382
|
|
394
383
|
it 'can be sorted by field non-destructively' do
|
395
384
|
sorted_entries = @small_bib.sort_by { |e| -e[:year].to_i }
|
396
|
-
sorted_entries.map(&:key).must_equal [
|
397
|
-
@small_bib.map(&:key).must_equal [
|
385
|
+
sorted_entries.map(&:key).must_equal %w[rails flanagan2008 segaran2007]
|
386
|
+
@small_bib.map(&:key).must_equal %w[flanagan2008 rails segaran2007]
|
398
387
|
end
|
399
388
|
end
|
400
389
|
|
@@ -406,7 +395,6 @@ module BibTeX
|
|
406
395
|
it 'converts LaTeX umlauts' do
|
407
396
|
@bib.convert(:latex)['rails'].keywords.must_be :==, 'rüby'
|
408
397
|
end
|
409
|
-
|
410
398
|
end
|
411
399
|
|
412
400
|
describe 'BibTeXML export' do
|
@@ -422,13 +410,12 @@ module BibTeX
|
|
422
410
|
end
|
423
411
|
|
424
412
|
it 'supports exporting to extended BibTeXML' do
|
425
|
-
@bib.to_xml(:
|
413
|
+
@bib.to_xml(extended: true).write(@bibtexml, 2)
|
426
414
|
@bibtexml.rewind
|
427
415
|
xml = REXML::Document.new(@bibtexml)
|
428
416
|
xml.root.namespace.must_be :==, 'http://bibtexml.sf.net/'
|
429
417
|
xml.root.get_elements('//bibtex:person').wont_be_empty
|
430
418
|
end
|
431
|
-
|
432
419
|
end
|
433
420
|
end
|
434
421
|
|
@@ -439,7 +426,7 @@ module BibTeX
|
|
439
426
|
|
440
427
|
it 'should respect options provided to initializer' do
|
441
428
|
assert_equal(@bib.add('@article{, title = test}'), @bib)
|
442
|
-
assert(
|
429
|
+
assert(@bib.entries.keys.none?(&:empty?))
|
443
430
|
end
|
444
431
|
end
|
445
432
|
end
|