bibtex-ruby 4.2.0 → 4.3.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/bibtex-ruby.gemspec +1 -1
- data/lib/bibtex/entry.rb +1 -0
- data/lib/bibtex/entry/citeproc_converter.rb +17 -9
- data/lib/bibtex/lexer.rb +0 -1
- data/lib/bibtex/utilities.rb +1 -1
- data/lib/bibtex/version.rb +1 -1
- data/test/bibtex/test_bibliography.rb +1 -1
- data/test/bibtex/test_entry.rb +13 -6
- data/test/bibtex/test_filters.rb +4 -6
- data/test/bibtex/test_names.rb +20 -22
- data/test/bibtex/test_value.rb +12 -12
- data/test/test_bibtex.rb +10 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc634591f21e9ea1d2e9a79a277e5637fa0f6c85
|
4
|
+
data.tar.gz: 4828e5209b60c9d582c8d63737f9ed15bb1331a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8132ee6e23158667aae83447cda153fc5e50157530f2193302141de3c5675bb80e4c79a27a0dfe6f5acc1c65815cf6c499dc5ffaf1f9fa4da6a30587e2da6642
|
7
|
+
data.tar.gz: df3f6095f2de0bfc5e43b18cb2561ee6977093782b6998b956d267898a893fe28680d94b0362cc4f3e7da538eb7fe2a4be43a5480025b4ba789c8b065e3b66b6
|
data/bibtex-ruby.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.authors = ['Sylvester Keil']
|
12
12
|
s.email = ['sylvester@keil.or.at']
|
13
13
|
s.homepage = 'http://inukshuk.github.com/bibtex-ruby'
|
14
|
-
s.license = 'GPL-3'
|
14
|
+
s.license = 'GPL-3.0'
|
15
15
|
|
16
16
|
s.summary = 'A BibTeX parser, converter and API for Ruby.'
|
17
17
|
s.description = <<-END_DESCRIPTION.gsub(/^\s+/, '')
|
data/lib/bibtex/entry.rb
CHANGED
@@ -72,6 +72,7 @@ module BibTeX
|
|
72
72
|
# Creates a new instance. If a hash is given, the entry is populated accordingly.
|
73
73
|
def initialize(attributes = {})
|
74
74
|
@fields = {}
|
75
|
+
@key = nil
|
75
76
|
|
76
77
|
self.type = attributes.delete(:bibtex_type) if attributes.has_key?(:bibtex_type)
|
77
78
|
self.key = attributes.delete(:bibtex_key) if attributes.has_key?(:bibtex_key)
|
@@ -62,15 +62,11 @@ class BibTeX::Entry::CiteProcConverter
|
|
62
62
|
bibtex.parse_month
|
63
63
|
|
64
64
|
bibtex.each_pair do |key, value|
|
65
|
-
|
66
|
-
|
65
|
+
convert key, value
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
else
|
71
|
-
hash[cp_key] = value.to_citeproc(options)
|
72
|
-
end
|
73
|
-
end
|
68
|
+
bibtex.inherited_fields.each do |key|
|
69
|
+
convert key, bibtex.parent.provide(key)
|
74
70
|
end
|
75
71
|
|
76
72
|
methods = self.class.instance_methods(false) - [:convert!, :hash]
|
@@ -146,10 +142,22 @@ class BibTeX::Entry::CiteProcConverter
|
|
146
142
|
end
|
147
143
|
end
|
148
144
|
|
149
|
-
|
145
|
+
private
|
150
146
|
|
151
147
|
attr_reader :bibtex, :options
|
152
148
|
|
149
|
+
def convert(key, value)
|
150
|
+
return if BibTeX::Entry::DATE_FIELDS.include?(key)
|
151
|
+
|
152
|
+
cp_key = CSL_FILTER[key].to_s
|
153
|
+
|
154
|
+
if hash.key?(cp_key)
|
155
|
+
hash[key] = value.to_citeproc(options)
|
156
|
+
else
|
157
|
+
hash[cp_key] = value.to_citeproc(options)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
153
161
|
def hash
|
154
162
|
@hash ||= {}
|
155
163
|
end
|
data/lib/bibtex/lexer.rb
CHANGED
data/lib/bibtex/utilities.rb
CHANGED
@@ -31,7 +31,7 @@ module BibTeX
|
|
31
31
|
# Delegates to BibTeX.open if the string is a filename or URI.
|
32
32
|
def parse(string, options = {}, &block)
|
33
33
|
case
|
34
|
-
when string.length < 260 && File.
|
34
|
+
when string.length < 260 && File.exist?(string)
|
35
35
|
Bibliography.open(string, options, &block)
|
36
36
|
when string =~ /^[a-z]+:\/\//i
|
37
37
|
Bibliography.open(string, options)
|
data/lib/bibtex/version.rb
CHANGED
data/test/bibtex/test_entry.rb
CHANGED
@@ -123,6 +123,12 @@ module BibTeX
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
describe '#to_citeproc' do
|
127
|
+
it 'includes inherited values' do
|
128
|
+
@bib['a1'].to_citeproc['container-title'].must_be :==, @bib['a'].title.to_s
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
126
132
|
describe '#save_inherited_fields' do
|
127
133
|
it 'copies referenced values to the entry' do
|
128
134
|
@bib['a1'].title = 'a1'
|
@@ -353,15 +359,16 @@ module BibTeX
|
|
353
359
|
end
|
354
360
|
|
355
361
|
describe 'given a filter object or a filter name' do
|
362
|
+
|
363
|
+
class SuffixB < BibTeX::Filter
|
364
|
+
def apply(value)
|
365
|
+
value.is_a?(::String) ? "#{value}b" : value
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
356
369
|
before do
|
357
370
|
@filter = Object.new
|
358
371
|
def @filter.apply (value); value.is_a?(::String) ? value.upcase : value; end
|
359
|
-
|
360
|
-
class SuffixB < BibTeX::Filter
|
361
|
-
def apply(value)
|
362
|
-
value.is_a?(::String) ? "#{value}b" : value
|
363
|
-
end
|
364
|
-
end
|
365
372
|
end
|
366
373
|
|
367
374
|
it 'supports arbitrary conversion' do
|
data/test/bibtex/test_filters.rb
CHANGED
@@ -2,12 +2,12 @@ require 'helper.rb'
|
|
2
2
|
|
3
3
|
module BibTeX
|
4
4
|
class FiltersTest < Minitest::Spec
|
5
|
-
|
5
|
+
|
6
6
|
it "should Filters should be singleton classes" do
|
7
7
|
assert_equal false, Filter.respond_to?(:new)
|
8
8
|
assert_equal Filter.instance.object_id, Filter.instance.object_id
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
describe 'Filters.resolve' do
|
12
12
|
it "should return the filter if a filter is given" do
|
13
13
|
assert_equal Filter.instance.object_id, Filters.resolve(Filter.instance).object_id
|
@@ -25,14 +25,12 @@ module BibTeX
|
|
25
25
|
assert_equal FooBar.instance.object_id, Filters.resolve('foobar').object_id
|
26
26
|
Filter.subclasses.delete(FooBar)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should return nil if there is no filter by that name" do
|
30
30
|
assert_equal nil, Filters.resolve(:foobar)
|
31
|
-
assert_equal nil, Filters.resolve(:upcase)
|
32
31
|
assert_equal nil, Filters.resolve('foobar')
|
33
32
|
assert_equal nil, Filters.resolve(nil)
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
|
-
end
|
36
|
+
end
|
data/test/bibtex/test_names.rb
CHANGED
@@ -4,11 +4,11 @@ require 'helper'
|
|
4
4
|
|
5
5
|
module BibTeX
|
6
6
|
class NamesTest < Minitest::Spec
|
7
|
-
|
7
|
+
|
8
8
|
before do
|
9
9
|
@poe = Name.new(:first => 'Edgar Allen', :last => 'Poe')
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe 'string behaviour' do
|
13
13
|
before do
|
14
14
|
@name = Name.new(:first => 'Charles Louis Xavier Joseph', :prefix => 'de la', :last => 'Vallee Poussin', :suffix => 'Jr.')
|
@@ -20,15 +20,15 @@ module BibTeX
|
|
20
20
|
assert_equal 'de la vallee poussin, jr., charles louis xavier joseph', @name.downcase!.to_s
|
21
21
|
end
|
22
22
|
it 'should implement gsub!' do
|
23
|
-
assert_equal 'dX la VallXX PoussXn, Jr., CharlXs LouXs XavXXr JosXph', @name.gsub!(/[ei]/, 'X').to_s
|
23
|
+
assert_equal 'dX la VallXX PoussXn, Jr., CharlXs LouXs XavXXr JosXph', @name.gsub!(/[ei]/, 'X').to_s
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
describe '#display_order' do
|
28
28
|
it 'returns the name as "first last"' do
|
29
29
|
@poe.display_order.must_be :==, 'Edgar Allen Poe'
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it 'accepts the :initials option' do
|
33
33
|
@poe.display_order(:initials => true).must_be :==, 'E.A. Poe'
|
34
34
|
end
|
@@ -38,16 +38,16 @@ module BibTeX
|
|
38
38
|
it 'returns the name as "last, first"' do
|
39
39
|
@poe.sort_order.must_be :==, 'Poe, Edgar Allen'
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it 'accepts the :initials option' do
|
43
43
|
@poe.sort_order(:initials => true).must_be :==, 'Poe, E.A.'
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
describe '#initials?' do
|
48
48
|
it 'returns true if the name contains a solely initials as a first name' do
|
49
49
|
@poe.initials?.must_equal false
|
50
|
-
|
50
|
+
|
51
51
|
@poe.first = 'Edgar A.'
|
52
52
|
@poe.initials?.must_equal false
|
53
53
|
|
@@ -61,7 +61,7 @@ module BibTeX
|
|
61
61
|
@poe.initials?.must_equal false
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
describe '#rename_if' do
|
66
66
|
it 'renames the name to the given attributes if no condition is given' do
|
67
67
|
@poe.rename_if({ :first => 'E.A.' }).first.must_equal 'E.A.'
|
@@ -86,21 +86,21 @@ module BibTeX
|
|
86
86
|
@poe.rename_if({ :first => 'E.A.' }) {|n| false}.first.wont_equal 'E.A.'
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
describe '#merge!' do
|
91
91
|
it 'does not merge duplicates' do
|
92
92
|
n1 = Names.new(@poe)
|
93
93
|
n2 = Names.new(@poe)
|
94
94
|
assert_equal @poe.to_s, n1.merge!(n2).to_s
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
it 'merges different names' do
|
98
98
|
n1 = Names.new(@poe)
|
99
99
|
n2 = Names.new(Name.new(:last => 'Plato'))
|
100
100
|
assert_equal "#{@poe.to_s} and Plato", n1.merge!(n2).to_s
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
describe '#normalize_initials' do
|
105
105
|
it 'returns normalized initials of existing initials only' do
|
106
106
|
Name.new(:first => 'Edgar A.', :last => 'Poe').normalize_initials.must_equal 'Edgar A.'
|
@@ -137,23 +137,21 @@ module BibTeX
|
|
137
137
|
Name.new(:first => 'E.A.', :last => 'Poe').extend_initials('Edgar', 'Poe').first.must_equal 'E.A.'
|
138
138
|
Name.new(:first => 'A.', :last => 'Poe').extend_initials('Edgar', 'Poe').first.must_equal 'A.'
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
it 'does not extend the first name if the last name or initials do not match' do
|
142
142
|
Name.new(:first => 'E.A.', :last => 'Poe').extend_initials('Edgar Allen', 'Poser').first.wont_equal 'Edgar Allen'
|
143
143
|
Name.new(:first => 'E.A.', :last => 'Poe').extend_initials('Edgar Ellen', 'Poe').first.wont_equal 'Edgar Ellen'
|
144
144
|
Name.new(:first => 'E.R.', :last => 'Poe').extend_initials('Edgar Allen', 'Poe').first.wont_equal 'Edgar Allen'
|
145
145
|
end
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
describe "conversions" do
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
value.upcase
|
153
|
-
end
|
149
|
+
class UpcaseAll < BibTeX::Filter
|
150
|
+
def apply (value)
|
151
|
+
value.upcase
|
154
152
|
end
|
155
153
|
end
|
156
|
-
|
154
|
+
|
157
155
|
describe "#convert" do
|
158
156
|
it "converts the value when given a filter instance" do
|
159
157
|
Names.parse('Poe and Hawthorne').convert(UpcaseAll.instance).to_s.must_be :==, 'POE and HAWTHORNE'
|
@@ -164,7 +162,7 @@ module BibTeX
|
|
164
162
|
end
|
165
163
|
end
|
166
164
|
end
|
167
|
-
|
165
|
+
|
168
166
|
end
|
169
|
-
|
167
|
+
|
170
168
|
end
|
data/test/bibtex/test_value.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
require 'helper.rb'
|
2
2
|
|
3
|
+
class Upcase < BibTeX::Filter
|
4
|
+
def apply(value)
|
5
|
+
value.is_a?(::String) ? value.upcase : value
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class SuffixA < BibTeX::Filter
|
10
|
+
def apply(value)
|
11
|
+
value.is_a?(::String) ? "#{value}a" : value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
module BibTeX
|
4
16
|
class ValueTest < Minitest::Spec
|
5
17
|
|
@@ -93,18 +105,6 @@ module BibTeX
|
|
93
105
|
|
94
106
|
describe "conversions" do
|
95
107
|
before do
|
96
|
-
class Upcase < BibTeX::Filter
|
97
|
-
def apply(value)
|
98
|
-
value.is_a?(::String) ? value.upcase : value
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
class SuffixA < BibTeX::Filter
|
103
|
-
def apply(value)
|
104
|
-
value.is_a?(::String) ? "#{value}a" : value
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
108
|
@values = [Value.new('foo'), Value.new('foo', :bar)]
|
109
109
|
end
|
110
110
|
|
data/test/test_bibtex.rb
CHANGED
@@ -3,7 +3,7 @@ require 'timeout'
|
|
3
3
|
|
4
4
|
module BibTeX
|
5
5
|
class TestBibtex < Minitest::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
8
|
end
|
9
9
|
|
@@ -37,25 +37,25 @@ module BibTeX
|
|
37
37
|
assert_equal('A {bunch {of} braces {in}} title', bib[:key03][:title])
|
38
38
|
#TODO missing assertions
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
# def test_errors
|
42
42
|
# bib = BibTeX.open(Test.fixtures(:errors), :debug => false)
|
43
43
|
# #refute_nil(bib)
|
44
44
|
# end
|
45
|
-
|
45
|
+
|
46
46
|
def test_bibdesk
|
47
47
|
bib = BibTeX::Bibliography.open(Test.fixtures(:bibdesk), :debug => false)
|
48
48
|
assert_equal 3, bib.length
|
49
49
|
assert_equal 'rails', bib[0].key
|
50
50
|
assert_equal '2010-08-05 10:06:32 +0200', bib[:dragon]['date-modified']
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def test_roundtrip
|
54
54
|
# file = File.read(Test.fixtures(:roundtrip))
|
55
55
|
# bib = BibTeX.parse(file, :debug => false)
|
56
56
|
# assert_equal file.gsub(/[\s]+/, ''), bib.to_s.gsub(/[\s]+/, '')
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def test_construct
|
60
60
|
# file = File.read(Test.fixtures(:roundtrip))
|
61
61
|
# bib = BibTeX::Bibliography.new
|
@@ -72,9 +72,9 @@ module BibTeX
|
|
72
72
|
# :title => 'Agile Web Development with Rails',
|
73
73
|
# :year => '2009'
|
74
74
|
# })
|
75
|
-
# assert_equal(file.gsub(/[\s]+/, ''), bib.to_s.gsub(/[\s]+/, ''))
|
75
|
+
# assert_equal(file.gsub(/[\s]+/, ''), bib.to_s.gsub(/[\s]+/, ''))
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def test_parse
|
79
79
|
bib = BibTeX::Bibliography.new
|
80
80
|
bib.add(BibTeX::Element.parse(%q( @string{ pragprog = "The Pragmatic Bookshelf" } )))
|
@@ -89,9 +89,9 @@ module BibTeX
|
|
89
89
|
series = {The Facets of Ruby},
|
90
90
|
title = {Agile Web Development with Rails},
|
91
91
|
year = {2009}
|
92
|
-
}
|
92
|
+
}
|
93
93
|
END
|
94
|
-
|
94
|
+
|
95
95
|
assert_equal(2, bib.length)
|
96
96
|
refute_nil(bib[:rails])
|
97
97
|
bib.replace_strings
|
@@ -114,7 +114,7 @@ EOF
|
|
114
114
|
@article{}
|
115
115
|
EOF
|
116
116
|
)
|
117
|
-
timeout(2) do
|
117
|
+
Timeout.timeout(2) do
|
118
118
|
BibTeX.parse(<<EOF, allow_missing_keys: true)
|
119
119
|
@article{},
|
120
120
|
@article{}
|
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.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: latex-decode
|
@@ -127,7 +127,7 @@ files:
|
|
127
127
|
- test/test_export.rb
|
128
128
|
homepage: http://inukshuk.github.com/bibtex-ruby
|
129
129
|
licenses:
|
130
|
-
- GPL-3
|
130
|
+
- GPL-3.0
|
131
131
|
metadata: {}
|
132
132
|
post_install_message:
|
133
133
|
rdoc_options: []
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.5.1
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: A BibTeX parser, converter and API for Ruby.
|