bibtex-ruby 4.0.8 → 4.0.9
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.
Potentially problematic release.
This version of bibtex-ruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/examples/bib2yaml.rb +2 -2
- data/lib/bibtex.rb +1 -1
- data/lib/bibtex/bibliography.rb +1 -1
- data/lib/bibtex/elements.rb +1 -1
- data/lib/bibtex/entry.rb +1 -1
- data/lib/bibtex/extensions.rb +5 -5
- data/lib/bibtex/filters/latex.rb +4 -4
- data/lib/bibtex/filters/linebreaks.rb +3 -3
- data/lib/bibtex/lexer.rb +36 -36
- data/lib/bibtex/name_parser.rb +16 -16
- data/lib/bibtex/names.rb +52 -52
- data/lib/bibtex/parser.rb +42 -42
- data/lib/bibtex/replaceable.rb +8 -8
- data/lib/bibtex/utilities.rb +10 -10
- data/lib/bibtex/value.rb +18 -10
- data/lib/bibtex/version.rb +2 -2
- data/test/benchmark.rb +12 -12
- data/test/bibtex/test_bibliography.rb +1 -1
- data/test/bibtex/test_elements.rb +13 -13
- metadata +2 -2
data/lib/bibtex/replaceable.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
#--
|
2
2
|
# BibTeX-Ruby
|
3
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
|
7
7
|
# the Free Software Foundation, either version 3 of the License, or
|
8
8
|
# (at your option) any later version.
|
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
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
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
#++
|
18
18
|
|
19
19
|
module BibTeX
|
20
|
-
|
20
|
+
|
21
21
|
#
|
22
22
|
# The Replaceable module provides methods that expose a Value attribute
|
23
23
|
# and the ability to join or replace the contained BibTeX symbols.
|
24
24
|
#
|
25
25
|
module Replaceable
|
26
26
|
extend Forwardable
|
27
|
-
|
27
|
+
|
28
28
|
attr_reader :value
|
29
29
|
|
30
30
|
def value=(value)
|
@@ -45,8 +45,8 @@ module BibTeX
|
|
45
45
|
@value << value
|
46
46
|
self
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
alias :v :value
|
50
|
-
|
50
|
+
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
data/lib/bibtex/utilities.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
#--
|
2
2
|
# BibTeX-Ruby
|
3
3
|
# Copyright (C) 2011 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
|
7
7
|
# the Free Software Foundation, either version 3 of the License, or
|
8
8
|
# (at your option) any later version.
|
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
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
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
#++
|
@@ -19,14 +19,14 @@
|
|
19
19
|
module BibTeX
|
20
20
|
|
21
21
|
class << self
|
22
|
-
|
22
|
+
|
23
23
|
# Opens a BibTeX file or URI and returns a corresponding +Bibliography+
|
24
24
|
# object or, if a block is given, yields the Bibliography to the block,
|
25
25
|
# ensuring that the file is saved.
|
26
26
|
def open(file, options = {}, &block)
|
27
27
|
Bibliography.open(file, options, &block)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Parses the given string and returns a corresponding +Bibliography+ object.
|
31
31
|
# Delegates to BibTeX.open if the string is a filename or URI.
|
32
32
|
def parse(string, options = {}, &block)
|
@@ -36,21 +36,21 @@ module BibTeX
|
|
36
36
|
Bibliography.parse(string, options)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# Returns true if the given file is a valid BibTeX bibliography.
|
41
41
|
def valid?(file)
|
42
42
|
Bibliography.open(file).valid?
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Parses the given string as a BibTeX name value and returns a Names object.
|
46
46
|
def names(string)
|
47
47
|
Names.parse(string)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
alias :name :names
|
51
51
|
alias :parse_name :names
|
52
52
|
alias :parse_names :names
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
55
|
|
56
|
-
end
|
56
|
+
end
|
data/lib/bibtex/value.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#--
|
4
4
|
# BibTeX-Ruby
|
5
|
-
# Copyright (C) 2010-
|
5
|
+
# Copyright (C) 2010-2015 Sylvester Keil <sylvester.keil.or.at>
|
6
6
|
#
|
7
7
|
# This program is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU General Public License as published by
|
@@ -94,7 +94,7 @@ module BibTeX
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def include_token?(token)
|
97
|
-
tokens.include?(token)
|
97
|
+
@tokens.include?(token)
|
98
98
|
end
|
99
99
|
|
100
100
|
def add(argument)
|
@@ -120,7 +120,7 @@ module BibTeX
|
|
120
120
|
|
121
121
|
[:strip!, :upcase!, :downcase!, :sub!, :gsub!, :chop!, :chomp!, :rstrip!].each do |method_id|
|
122
122
|
define_method(method_id) do |*arguments, &block|
|
123
|
-
tokens.each do |part|
|
123
|
+
@tokens.each do |part|
|
124
124
|
part.send(method_id, *arguments, &block) unless part.nil?
|
125
125
|
end
|
126
126
|
self
|
@@ -193,7 +193,7 @@ module BibTeX
|
|
193
193
|
def value
|
194
194
|
case
|
195
195
|
when numeric?
|
196
|
-
|
196
|
+
to_i
|
197
197
|
when atomic?
|
198
198
|
@tokens[0]
|
199
199
|
else
|
@@ -204,7 +204,7 @@ module BibTeX
|
|
204
204
|
alias :v :value
|
205
205
|
|
206
206
|
def inspect
|
207
|
-
"#<#{self.class} #{tokens.map(&:inspect).join(', ')}>"
|
207
|
+
"#<#{self.class} #{@tokens.map(&:inspect).join(', ')}>"
|
208
208
|
end
|
209
209
|
|
210
210
|
# Returns true if the Value is empty or consists of a single token.
|
@@ -238,7 +238,11 @@ module BibTeX
|
|
238
238
|
|
239
239
|
# Returns true if the Value's content is numeric.
|
240
240
|
def numeric?
|
241
|
-
atomic? && tokens[0] =~ /^\s*[+-]?\d+[\/\.]?\d*\s*$/
|
241
|
+
atomic? && @tokens[0] =~ /^\s*[+-]?\d+[\/\.]?\d*\s*$/
|
242
|
+
end
|
243
|
+
|
244
|
+
def to_i
|
245
|
+
@tokens[0].to_i
|
242
246
|
end
|
243
247
|
|
244
248
|
def to_citeproc (options = {})
|
@@ -247,14 +251,14 @@ module BibTeX
|
|
247
251
|
|
248
252
|
# Returns true if the Value contains at least one symbol.
|
249
253
|
def symbol?
|
250
|
-
tokens.detect { |v| v.is_a?(Symbol) }
|
254
|
+
@tokens.detect { |v| v.is_a?(Symbol) }
|
251
255
|
end
|
252
256
|
|
253
257
|
alias has_symbol? symbol?
|
254
258
|
|
255
259
|
# Returns all symbols contained in the Value.
|
256
260
|
def symbols
|
257
|
-
tokens.select { |v| v.is_a?(Symbol) }
|
261
|
+
@tokens.select { |v| v.is_a?(Symbol) }
|
258
262
|
end
|
259
263
|
|
260
264
|
# Returns a new Value with all string values converted according to the given filter(s).
|
@@ -266,7 +270,7 @@ module BibTeX
|
|
266
270
|
def convert! (*filters)
|
267
271
|
filters.flatten.each do |filter|
|
268
272
|
f = Filters.resolve!(filter)
|
269
|
-
tokens.map! { |t| f.apply(t) }
|
273
|
+
@tokens.map! { |t| f.apply(t) }
|
270
274
|
end
|
271
275
|
|
272
276
|
self
|
@@ -286,7 +290,11 @@ module BibTeX
|
|
286
290
|
end
|
287
291
|
|
288
292
|
def <=> (other)
|
289
|
-
|
293
|
+
if numeric? && other.respond_to?(:numeric?) && other.numeric?
|
294
|
+
to_i <=> other.to_i
|
295
|
+
else
|
296
|
+
to_s <=> other.to_s
|
297
|
+
end
|
290
298
|
end
|
291
299
|
|
292
300
|
end
|
data/lib/bibtex/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# BibTeX-Ruby
|
3
|
-
# Copyright (C) 2010-
|
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
|
@@ -20,7 +20,7 @@ module BibTeX
|
|
20
20
|
module Version
|
21
21
|
MAJOR = 4
|
22
22
|
MINOR = 0
|
23
|
-
PATCH =
|
23
|
+
PATCH = 9
|
24
24
|
BUILD = nil
|
25
25
|
|
26
26
|
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
|
data/test/benchmark.rb
CHANGED
@@ -34,7 +34,7 @@ format = Benchmark.const_defined?(:FMTSTR) ? Benchmark::FMTSTR : Benchmark::FORM
|
|
34
34
|
Benchmark.benchmark((" "*15) + CAPTION, 7, format, '%14s:' % 'sum(f)', '%14s:' % 'sum(g)') do |b|
|
35
35
|
|
36
36
|
1.step(n,k) do |i|
|
37
|
-
|
37
|
+
|
38
38
|
f << b.report('%14s:' % "f(#{i})") do
|
39
39
|
i.times do
|
40
40
|
lexer.data = input
|
@@ -44,41 +44,41 @@ Benchmark.benchmark((" "*15) + CAPTION, 7, format, '%14s:' % 'sum(f)', '%14s:' %
|
|
44
44
|
end
|
45
45
|
|
46
46
|
data = input * i
|
47
|
-
|
47
|
+
|
48
48
|
g << b.report('%14s:' % "g(#{i})") do
|
49
49
|
lexer.data = data
|
50
50
|
lexer.analyse
|
51
51
|
# BibTeX::Parser.new.parse(data)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
[f.inject(:+), g.inject(:+)]
|
57
57
|
end
|
58
58
|
|
59
59
|
# require 'gnuplot'
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# f = f.map(&:total)
|
62
62
|
# g = g.map(&:total)
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# x = 1.step(n,k).to_a
|
65
|
-
#
|
65
|
+
#
|
66
66
|
# Gnuplot.open do |gp|
|
67
67
|
# Gnuplot::Plot.new(gp) do |plot|
|
68
|
-
#
|
68
|
+
#
|
69
69
|
# plot.title 'BibTeX-Ruby Benchmark'
|
70
70
|
# plot.ylabel 't'
|
71
71
|
# plot.xlabel 'n'
|
72
|
-
#
|
72
|
+
#
|
73
73
|
# plot.data << Gnuplot::DataSet.new([x,f]) do |ds|
|
74
74
|
# ds.with = 'linespoints'
|
75
75
|
# ds.title = 'f'
|
76
76
|
# end
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# plot.data << Gnuplot::DataSet.new([x,g]) do |ds|
|
79
79
|
# ds.with = 'linespoints'
|
80
80
|
# ds.title = 'g'
|
81
81
|
# end
|
82
|
-
#
|
82
|
+
#
|
83
83
|
# end
|
84
|
-
# end
|
84
|
+
# end
|
@@ -1,49 +1,49 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
module BibTeX
|
4
|
-
|
4
|
+
|
5
5
|
class ElementTest < Minitest::Spec
|
6
|
-
|
6
|
+
|
7
7
|
describe '.parse' do
|
8
|
-
|
8
|
+
|
9
9
|
it 'accepts a BibTeX string' do
|
10
10
|
Element.parse('@misc{x,},@misc{y,}').length.must_be :==, 2
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it 'accepts an Element' do
|
14
14
|
Element.parse(Comment.new('blah')).length.must_be :==, 1
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it 'accepts a Hash and returns an Entry' do
|
18
18
|
Element.parse({ :bibtex_type => :book })[0].type.must_be :==, :book
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it 'accepts an array of hashes' do
|
22
22
|
Element.parse([{ :bibtex_type => :book }, { :bibtex_type => :misc }])[1].type.must_be :==, :misc
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
end
|
28
28
|
|
29
29
|
class PreambleTest < Minitest::Spec
|
30
|
-
|
30
|
+
|
31
31
|
describe 'a new preamble instance' do
|
32
32
|
before do
|
33
33
|
@preamble = Preamble.new
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it 'should not be nil' do
|
37
37
|
assert @preamble
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe 'given a set of @preambles' do
|
42
42
|
before do
|
43
43
|
@bib = BibTeX.open(Test.fixtures(:preamble))
|
44
44
|
@preambles = @bib.preambles
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it 'should support round-trips of all parsed preambles' do
|
48
48
|
assert_equal %q[@preamble{ "This bibliography was created \today" }], @preambles[0].to_s
|
49
49
|
assert_equal %q[@preamble{ "Bib\TeX" }], @preambles[1].to_s
|
@@ -60,5 +60,5 @@ module BibTeX
|
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bibtex-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: latex-decode
|