bibtex-ruby 1.2.0 → 1.2.1
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.
- data/History.txt +14 -0
- data/README.md +12 -10
- data/bibtex-ruby.gemspec +1 -1
- data/lib/bibtex.rb +15 -13
- data/lib/bibtex/bibliography.rb +3 -1
- data/lib/bibtex/elements.rb +7 -1
- data/lib/bibtex/entry.rb +11 -4
- data/lib/bibtex/extensions.rb +5 -5
- data/lib/bibtex/lexer.rb +1 -1
- data/lib/bibtex/version.rb +1 -1
- data/test/test_entry.rb +53 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 1.2.1 / 2011-02-26
|
2
|
+
|
3
|
+
* Fixed several MacRuby compliancy issues.
|
4
|
+
* Fixed compatibility issues and BibTeX parsing of Name tokens (by lyro)
|
5
|
+
|
6
|
+
=== 1.2.0 / 2011-02-12
|
7
|
+
|
8
|
+
* Switched to using bundler.
|
9
|
+
* Improved BibTeX::Entry constructor (supports hashes for intuitive assignments).
|
10
|
+
* Added top-level methods BibTeX.parse, BibTeX.open, BibTeX.valid? and
|
11
|
+
BibTeX::Entry.parse.
|
12
|
+
* Rewrote StringReplacement extensions to use monkey patching of Arrays.
|
13
|
+
* See README.md or unit tests for updated code examples.
|
14
|
+
|
1
15
|
=== 1.1.2 / 2011-01-27
|
2
16
|
|
3
17
|
* Added dynamic ghost methods to BibTeX::Entry for more convenient access
|
data/README.md
CHANGED
@@ -18,15 +18,15 @@ Quickstart
|
|
18
18
|
=> true
|
19
19
|
> bib = BibTeX.open('./ruby.bib')
|
20
20
|
=> book{pickaxe,
|
21
|
-
address
|
22
|
-
author {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
|
23
|
-
date-added
|
24
|
-
date-modified
|
25
|
-
keywords
|
26
|
-
publisher
|
27
|
-
series
|
28
|
-
title
|
29
|
-
year
|
21
|
+
address = {Raleigh, North Carolina},
|
22
|
+
author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
|
23
|
+
date-added = {2010-08-05 09:54:07 0200},
|
24
|
+
date-modified = {2010-08-05 10:07:01 0200},
|
25
|
+
keywords = {ruby},
|
26
|
+
publisher = {The Pragmatic Bookshelf},
|
27
|
+
series = {The Facets of Ruby},
|
28
|
+
title = {Programming Ruby 1.9: The Pragmatic Programmers Guide},
|
29
|
+
year = {2009}
|
30
30
|
}
|
31
31
|
> bib[:pickaxe].year
|
32
32
|
=> "2009"
|
@@ -282,7 +282,9 @@ These represent proper BibTeX objects (e.g., @book, @collection, etc.).
|
|
282
282
|
Credits
|
283
283
|
-------
|
284
284
|
|
285
|
-
The BibTeX-Ruby package was written by [Sylvester Keil](http://sylvester.keil.or.at/)
|
285
|
+
The BibTeX-Ruby package was written by [Sylvester Keil](http://sylvester.keil.or.at/),
|
286
|
+
with contributions by [Frank Fischer](https://github.com/lyro).
|
287
|
+
|
286
288
|
|
287
289
|
License
|
288
290
|
-------
|
data/bibtex-ruby.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'bibtex/version'
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'bibtex-ruby'
|
9
|
-
s.version = BibTeX::Version::STRING
|
9
|
+
s.version = BibTeX::Version::STRING.dup
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.authors = ['Sylvester Keil']
|
12
12
|
s.email = 'http://sylvester.keil.or.at'
|
data/lib/bibtex.rb
CHANGED
@@ -20,6 +20,9 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
20
20
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
21
21
|
|
22
22
|
|
23
|
+
require 'bibtex/version'
|
24
|
+
require 'logger'
|
25
|
+
|
23
26
|
# = BibTeX
|
24
27
|
#
|
25
28
|
# This module encompasses a parser for BibTeX files and
|
@@ -32,8 +35,6 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
32
35
|
# License:: GNU GPL 3.0
|
33
36
|
#
|
34
37
|
module BibTeX
|
35
|
-
require 'bibtex/version'
|
36
|
-
require 'logger'
|
37
38
|
|
38
39
|
#
|
39
40
|
# An instance of the Ruby core class +Logger+.
|
@@ -43,16 +44,17 @@ module BibTeX
|
|
43
44
|
Log.level = ENV.has_key?('DEBUG') ? Logger::DEBUG : Logger::WARN
|
44
45
|
Log.datetime_format = "%Y-%m-%d %H:%M:%S"
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
# Debugger.start
|
47
|
+
def self.log; BibTeX::Log end
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
require 'bibtex/error'
|
54
|
-
require 'bibtex/parser'
|
55
|
-
require 'bibtex/bibliography'
|
56
|
-
require 'bibtex/utilities'
|
50
|
+
# Load debugger
|
51
|
+
# require 'ruby-debug'
|
52
|
+
# Debugger.start
|
57
53
|
|
58
|
-
|
54
|
+
require 'bibtex/extensions'
|
55
|
+
require 'bibtex/elements'
|
56
|
+
require 'bibtex/entry'
|
57
|
+
require 'bibtex/error'
|
58
|
+
require 'bibtex/parser'
|
59
|
+
require 'bibtex/bibliography'
|
60
|
+
require 'bibtex/utilities'
|
data/lib/bibtex/bibliography.rb
CHANGED
data/lib/bibtex/elements.rb
CHANGED
@@ -22,7 +22,8 @@ module BibTeX
|
|
22
22
|
# The base class for BibTeX objects.
|
23
23
|
#
|
24
24
|
class Element
|
25
|
-
|
25
|
+
include Comparable
|
26
|
+
|
26
27
|
attr_reader :bibliography
|
27
28
|
|
28
29
|
# Returns an array of BibTeX elements.
|
@@ -76,6 +77,11 @@ module BibTeX
|
|
76
77
|
@bibliography = nil
|
77
78
|
self
|
78
79
|
end
|
80
|
+
|
81
|
+
def <=>(other)
|
82
|
+
(type_comparison = self.class.name <=> other.class.name) == 0 ? self.to_s <=> other.to_s : type_comparison
|
83
|
+
end
|
84
|
+
|
79
85
|
end
|
80
86
|
|
81
87
|
|
data/lib/bibtex/entry.rb
CHANGED
@@ -51,6 +51,8 @@ module BibTeX
|
|
51
51
|
self.key = hash.delete(:key) if hash.has_key?(:key)
|
52
52
|
|
53
53
|
hash.each { |k, v| add(k.to_sym, v) }
|
54
|
+
|
55
|
+
yield self if block_given?
|
54
56
|
end
|
55
57
|
|
56
58
|
# Sets the key of the entry
|
@@ -61,18 +63,18 @@ module BibTeX
|
|
61
63
|
|
62
64
|
# Sets the type of the entry.
|
63
65
|
def type=(type)
|
64
|
-
raise(ArgumentError, "BibTeX::Entry type must be
|
65
|
-
@type = type
|
66
|
+
raise(ArgumentError, "BibTeX::Entry type must be convertible to Symbol; was: #{type.class.name}.") unless type.respond_to?(:to_sym)
|
67
|
+
@type = type.to_sym
|
66
68
|
end
|
67
69
|
|
68
70
|
def method_missing(name, *args)
|
69
71
|
return self[name] if @fields.has_key?(name)
|
70
|
-
return self.send(:add, name.to_s.chop.to_sym, args[0]) if name.match(/=$/)
|
72
|
+
return self.send(:add, name.to_s.chop.to_sym, args[0]) if name.to_s.match(/=$/)
|
71
73
|
super
|
72
74
|
end
|
73
75
|
|
74
76
|
def respond_to?(method)
|
75
|
-
@fields.has_key?(method.to_sym) || method.match(/=$/) || super
|
77
|
+
@fields.has_key?(method.to_sym) || method.to_s.match(/=$/) || super
|
76
78
|
end
|
77
79
|
|
78
80
|
# Returns the value of the field with the given name.
|
@@ -168,5 +170,10 @@ module BibTeX
|
|
168
170
|
end
|
169
171
|
xml
|
170
172
|
end
|
173
|
+
|
174
|
+
def <=>(other)
|
175
|
+
self.type != other.type ? self.type <=> other.type : self.key != other.key ? self.key <=> other.key : self.to_s <=> other.to_s
|
176
|
+
end
|
177
|
+
|
171
178
|
end
|
172
179
|
end
|
data/lib/bibtex/extensions.rb
CHANGED
@@ -24,8 +24,8 @@ module BibTeX
|
|
24
24
|
module Extensions
|
25
25
|
|
26
26
|
def self.string_replacement(obj)
|
27
|
-
raise(ArgumentError, "StringReplacement should only be injected into instances of Array, not #{obj.class}.") unless obj.is_a?(Array)
|
28
|
-
class << obj; include StringReplacement end
|
27
|
+
raise(ArgumentError, "StringReplacement should only be injected into instances of Array, not #{obj.class}.") unless obj.is_a?(::Array)
|
28
|
+
class << obj; include ::BibTeX::Extensions::StringReplacement end
|
29
29
|
obj
|
30
30
|
end
|
31
31
|
|
@@ -36,16 +36,16 @@ module BibTeX
|
|
36
36
|
|
37
37
|
options[:quotes] ||= [nil,nil]
|
38
38
|
|
39
|
-
if self.length == 1 && !self[0].is_a?(Symbol)
|
39
|
+
if self.length == 1 && !self[0].is_a?(::Symbol)
|
40
40
|
[options[:quotes][0], self[0], options[:quotes][1]].join
|
41
41
|
else
|
42
|
-
self.map { |s| s.is_a?(Symbol) ? s.to_s : %Q("#{ s }") }.join(' # ')
|
42
|
+
self.map { |s| s.is_a?(::Symbol) ? s.to_s : %Q("#{ s }") }.join(' # ')
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
# Replaces all string constants which are defined in +hash+.
|
47
47
|
def replace_strings(hash)
|
48
|
-
Extensions.string_replacement(self.map { |s| s.is_a?(Symbol) && hash.has_key?(s) ? hash[s] : s }.flatten)
|
48
|
+
Extensions.string_replacement(self.map { |s| s.is_a?(::Symbol) && hash.has_key?(s) ? hash[s] : s }.flatten)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Joins consecutive strings separated by '#'.
|
data/lib/bibtex/lexer.rb
CHANGED
@@ -178,7 +178,7 @@ module BibTeX
|
|
178
178
|
push [:SHARP,'#']
|
179
179
|
when self.src.scan(/\d+/o)
|
180
180
|
push [:NUMBER,self.src.matched]
|
181
|
-
when self.src.scan(/[a-z\d
|
181
|
+
when self.src.scan(/[a-z\d\/:_!$\.%&*-]+/io)
|
182
182
|
push [:NAME,self.src.matched]
|
183
183
|
when self.src.scan(/"/o)
|
184
184
|
self.mode = :literal
|
data/lib/bibtex/version.rb
CHANGED
data/test/test_entry.rb
CHANGED
@@ -42,4 +42,57 @@ class TestEntry < MiniTest::Unit::TestCase
|
|
42
42
|
assert_equal(expected, bib.data[0].author)
|
43
43
|
end
|
44
44
|
|
45
|
+
def test_creation_simple
|
46
|
+
expected = "@book{raven,\n author = {Poe, Edgar A.},\n title = {The Raven}\n}\n"
|
47
|
+
|
48
|
+
entry = BibTeX::Entry.new
|
49
|
+
entry.type = :book
|
50
|
+
entry.key = 'raven'
|
51
|
+
entry.author = 'Poe, Edgar A.'
|
52
|
+
entry.title = 'The Raven'
|
53
|
+
|
54
|
+
assert_equal(expected, entry.to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_creation_from_hash
|
58
|
+
expected = "@book{raven,\n author = {Poe, Edgar A.},\n title = {The Raven}\n}\n"
|
59
|
+
|
60
|
+
entry = BibTeX::Entry.new({
|
61
|
+
:type => 'book',
|
62
|
+
:key => 'raven',
|
63
|
+
:author => 'Poe, Edgar A.',
|
64
|
+
:title => 'The Raven'
|
65
|
+
})
|
66
|
+
|
67
|
+
assert_equal(expected, entry.to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_creation_from_block
|
71
|
+
expected = "@book{raven,\n author = {Poe, Edgar A.},\n title = {The Raven}\n}\n"
|
72
|
+
|
73
|
+
entry = BibTeX::Entry.new do |e|
|
74
|
+
e.type = :book
|
75
|
+
e.key = 'raven'
|
76
|
+
e.author = 'Poe, Edgar A.'
|
77
|
+
e.title = 'The Raven'
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_equal(expected, entry.to_s)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_sorting
|
84
|
+
entries = []
|
85
|
+
entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven3', :author => 'Poe, Edgar A.', :title => 'The Raven'})
|
86
|
+
entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven2', :author => 'Poe, Edgar A.', :title => 'The Raven'})
|
87
|
+
entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven1', :author => 'Poe, Edgar A.', :title => 'The Raven'})
|
88
|
+
entries << BibTeX::Entry.new({ :type => 'book', :key => 'raven1', :author => 'Poe, Edgar A.', :title => 'The Aven'})
|
89
|
+
|
90
|
+
entries.sort!
|
91
|
+
|
92
|
+
assert_equal(%w{ raven1 raven1 raven2 raven3 }, entries.map(&:key))
|
93
|
+
assert_equal([ 'The Aven', 'The Raven' ], entries.map(&:title)[0,2])
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
45
98
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bibtex-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sylvester Keil
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-06 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|