bibtex-ruby 2.0.2 → 2.0.3

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.

@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bibtex-ruby (2.0.1)
4
+ bibtex-ruby (2.0.2)
5
5
  latex-decode (>= 0.0.6)
6
6
  multi_json (~> 1.0)
7
7
 
@@ -27,7 +27,7 @@ GEM
27
27
  gnuplot (2.3.6)
28
28
  json (1.5.4)
29
29
  json (1.5.4-java)
30
- latex-decode (0.0.9)
30
+ latex-decode (0.0.10)
31
31
  unicode (~> 0.4)
32
32
  linecache (0.46)
33
33
  rbx-require-relative (> 0.0.4)
@@ -1,3 +1,8 @@
1
+ 2.0.3 / 2011-12-13
2
+ ==================
3
+
4
+ * Added new entry wildcard "@*" to queries (kudos to @vanto)
5
+
1
6
  2.0.2 / 2011-11-25
2
7
  ==================
3
8
 
data/README.md CHANGED
@@ -58,38 +58,19 @@ one of [many different styles](https://github.com/citation-style-language/styles
58
58
  Guide. Raleigh, North Carolina: The Pragmatic Bookshelf, 2009."
59
59
 
60
60
 
61
- Installation
62
- ------------
63
-
64
- If you just want to use it:
65
-
66
- $ [sudo] gem install bibtex-ruby
67
-
68
- If you want to work with the sources:
69
-
70
- $ git clone http://github.com/inukshuk/bibtex-ruby.git
71
- $ cd bibtex-ruby
72
- $ [sudo] bundle install
73
- $ rake racc
74
- $ rake rdoc
75
- $ rake features
76
- $ rake test
77
-
78
- For extra credit, fork the
79
- [project on GitHub](http://github.com/inukshuk/bibtex-ruby.git).
80
-
81
61
 
82
62
  Requirements
83
63
  ------------
84
64
 
85
- * The parser generator [racc](http://i.loveruby.net/en/projects/racc/) is
86
- required to generate the BibTeX parser and the name parser.
87
-
88
- The BibTeX-Ruby gem has been tested on Ruby versions 1.8.7 and 1.9.2; it has
65
+ The BibTeX-Ruby gem has been tested on Ruby 1.8 and 1.9; it has
89
66
  been confirmed to work with REE, JRuby, and Rubinius;
90
67
  however, there have been some [issues](https://github.com/inukshuk/bibtex-ruby/issues)
91
68
  with MacRuby implementations.
92
69
 
70
+ The parser generator [racc](http://i.loveruby.net/en/projects/racc/) is
71
+ required to generate the BibTeX parser and the name parser; you do not need
72
+ to install it to use the bibtex-ruby gem.
73
+
93
74
 
94
75
 
95
76
  Usage
@@ -453,18 +434,31 @@ You can check out a copy of the latest code using Git:
453
434
 
454
435
  If you've found a bug or have a question, please open an issue on the
455
436
  [BibTeX-Ruby issue tracker](http://github.com/inukshuk/bibtex-ruby/issues).
456
- Or, for extra credit, clone the BibTeX-Ruby repository, write a failing
437
+ For extra credit, clone the BibTeX-Ruby repository, write a failing
457
438
  example, or cucumber feature, fix the bug and submit a pull request (for
458
439
  useful examples, take a look at the cucumber features in the
459
440
  [features/issues/](https://github.com/inukshuk/bibtex-ruby/blob/master/features/issues)
460
441
  directory).
461
442
 
443
+ To run the tests and cucumber examples execute these commands (from within
444
+ the bibtex-ruby directory):
445
+
446
+ $ [sudo] gem install bundler
447
+ $ [sudo] bundle install
448
+ $ bundle exec cucumber
449
+ $ bundle exec rake test
450
+
451
+ To execute the test suite continuously while you're working run:
452
+
453
+ $ bundle exec watchr auto.watchr
454
+
455
+
462
456
 
463
457
  Credits
464
458
  -------
465
459
 
466
- The BibTeX-Ruby package was written by [Sylvester Keil](http://sylvester.keil.or.at/);
467
- kudos and thanks to all [contributors](https://github.com/inukshuk/bibtex-ruby/contributors)!
460
+ Copyright 2011 [Sylvester Keil](http://sylvester.keil.or.at/).
468
461
 
469
- BibTeX-Ruby is distributed under the terms and conditions of the GPL. See
462
+ BibTeX-Ruby was written by many awesome [contributors](https://github.com/inukshuk/bibtex-ruby/contributors)
463
+ and is distributed under the terms and conditions of the GNU GPL. See
470
464
  LICENSE for details.
@@ -53,4 +53,10 @@ Feature: Searching in BibTeX bibliographies
53
53
  Then there should be exactly 0 matches
54
54
  When I search for "@book, @article"
55
55
  Then there should be exactly 3 matches
56
+ When I search for "@entry"
57
+ Then there should be exactly 3 matches
58
+ When I search for "@*"
59
+ Then there should be exactly 3 matches
60
+ When I search for "@*[year=2007]"
61
+ Then there should be exactly 1 match
56
62
 
@@ -335,33 +335,52 @@ module BibTeX
335
335
  root = REXML::Element.new('bibtex:file')
336
336
  root.add_namespace('bibtex', 'http://bibtexml.sf.net/')
337
337
 
338
- each { |e| root.add_element(e.to_xml(options)) }
338
+ each { |e| root.add_element(e.to_xml(options)) if e.is_a?(Entry) }
339
339
 
340
340
  xml.add_element(root)
341
341
  xml
342
342
  end
343
343
 
344
+ # call-seq:
345
+ # bib.query() #=> returns all elements
346
+ # bib.query('@book') #=> returns all books
347
+ # bib.query('@entry') #=> returns all entries (books, articles etc.)
348
+ # bib.query('@*') #=> same as above
349
+ # bib.query(:first, '@book, @article')
350
+ # #=> returns the first book or article or nil
351
+ # bib.query('@book[year=2011], @article)
352
+ # #=> returns all books published in 2011 and all articles
353
+ # bib.query('@book, @article) { |o| o.year == '2011' }
354
+ # #=> returns all books and articles published in 2011
355
+ # bib.query('@book[year=2011], @article[year=2011])
356
+ # #=> same as above without using a block
357
+ #
344
358
  # Returns objects in the Bibliography which match the given selector and,
345
359
  # optionally, the conditions specified in the given block.
346
360
  #
347
- # call-seq:
348
- # bib.query() #=> returns all objects
349
- # bib.query(:all) #=> returns all objects
350
- # bib.query(:first) #=> returns the first object
351
- # bib.query('@book') #=> returns all books
352
- # bib.query(:first, '@book, @article')
353
- # #=> returns the first book or article
354
- # bib.query('@book[year=2011], @article)
355
- # #=> returns all books published in 2011 and all articles
356
- # bib.query('@book, @article) { |o| o.year == '2011' }
357
- # #=> returns all books and articles published in 2011
358
- # bib.query('@book[year=2011], @article[year=2011])
359
- # #=> same as above without using a block
361
+ # Queries offer syntactic sugar for common enumerator invocations:
362
+ #
363
+ # >> bib.query(:all, '@book')
364
+ # => same as bib.select { |b| b.has_type?(:book) }
365
+ # >> bib.query('@book')
366
+ # => same as above
367
+ # >> bib.query(:first, '@book')
368
+ # => same as bib.detect { |b| b.has_type?(:book) }
369
+ # >> bib.query(:none, '@book')
370
+ # => same as bib.reject { |b| b.has_type?(:book) }
360
371
  #
361
372
  def query(*arguments, &block)
362
- raise ArgumentError, "wrong number of arguments (#{arguments.length} for 0..2)" unless arguments.length.between?(0,2)
363
-
364
- q, selector = arguments.reverse
373
+ case arguments.length
374
+ when 0
375
+ selector, q = :all, nil
376
+ when 1
377
+ selector, q = :all, arguments[0]
378
+ when 2
379
+ selector, q = arguments
380
+ else
381
+ raise ArgumentError, "wrong number of arguments (#{arguments.length} for 0..2)"
382
+ end
383
+
365
384
  filter = block ? Proc.new { |e| e.match?(q) && block.call(e) } :
366
385
  Proc.new { |e| e.match?(q) }
367
386
 
@@ -79,7 +79,7 @@ module BibTeX
79
79
 
80
80
  # Returns true if the element matches the given query.
81
81
  def matches?(query)
82
- return true if !query || query.respond_to?(:empty?) && query.empty?
82
+ return true if query.nil? || query.respond_to?(:empty?) && query.empty?
83
83
 
84
84
  case query
85
85
  when Symbol
@@ -88,8 +88,8 @@ module BibTeX
88
88
  query == self
89
89
  when Regexp
90
90
  to_s.match(query)
91
- when /@(\w+)(?:\[([^\]]*)\])?/
92
- query.scan(/@(\w+)(?:\[([^\]]*)\])?/).any? do |type, condition|
91
+ when /@(\*|\w+)(?:\[([^\]]*)\])?/
92
+ query.scan(/@(\*|\w+)(?:\[([^\]]*)\])?/).any? do |type, condition|
93
93
  has_type?(type) && ( condition.nil? || meets?(condition.split(/,\s*/)) )
94
94
  end
95
95
  when /^\/(.+)\/$/
@@ -192,7 +192,7 @@ module BibTeX
192
192
  end
193
193
 
194
194
  def has_type?(type)
195
- type.to_s.match(/^entry$/i) || @type == type.to_sym || super
195
+ type.to_s.match(/^(?:entry|\*)$/i) || @type == type.to_sym || super
196
196
  end
197
197
 
198
198
  alias type? has_type?
@@ -54,6 +54,7 @@ module BibTeX
54
54
 
55
55
  def_delegators :to_s, :=~, :===, *String.instance_methods(false).reject { |m| m =~ /^\W|^length$|^dup$|!$/ }
56
56
  def_delegators :@tokens, :[], :length
57
+ def_delegator :@tokens, :each, :each_token
57
58
 
58
59
  def initialize(*arguments)
59
60
  @tokens = []
@@ -212,8 +213,6 @@ module BibTeX
212
213
  tokens.select { |v| v.is_a?(Symbol) }
213
214
  end
214
215
 
215
- def each_token; tokens.each; end
216
-
217
216
  # Returns a new Value with all string values converted according to the given filter.
218
217
  def convert (filter)
219
218
  dup.convert!(filter)
@@ -18,6 +18,6 @@
18
18
 
19
19
  module BibTeX
20
20
  module Version
21
- STRING = '2.0.2'.freeze
21
+ STRING = '2.0.3'.freeze
22
22
  end
23
23
  end
@@ -63,6 +63,7 @@ module BibTeX
63
63
  year={2007},
64
64
  publisher={O'Reilly}
65
65
  }
66
+ @string{ foo = "foobar" }
66
67
  END
67
68
  end
68
69
 
@@ -144,6 +145,22 @@ module BibTeX
144
145
  assert_equal @bib.length, BibTeX.open(tmp.path).length
145
146
  end
146
147
 
148
+ describe '#query' do
149
+
150
+ it 'returns all elements when passed no arguments' do
151
+ @bib.query.length.must_be :==, 4
152
+ end
153
+
154
+ it 'returns all elements when passed :all and an empty condition' do
155
+ @bib.query(:all, '').length.must_be :==, 4
156
+ end
157
+
158
+ it 'returns all entries when passed a * wildcard' do
159
+ @bib.query('@*').length.must_be :==, 3
160
+ end
161
+
162
+ end
163
+
147
164
  describe 'given a filter' do
148
165
  before do
149
166
  @filter = Object
@@ -28,6 +28,7 @@ module BibTeX
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)
31
32
  assert_equal nil, Filters.resolve('foobar')
32
33
  assert_equal nil, Filters.resolve(nil)
33
34
  end
@@ -23,7 +23,7 @@ module BibTeX
23
23
 
24
24
  describe "conversions" do
25
25
  before do
26
- class Upcase < BibTeX::Filter
26
+ class UpcaseAll < BibTeX::Filter
27
27
  def apply (value)
28
28
  value.upcase
29
29
  end
@@ -32,7 +32,7 @@ module BibTeX
32
32
 
33
33
  describe "#convert" do
34
34
  it "converts the value when given a filter instance" do
35
- Names.parse('Poe and Hawthorne').convert(Upcase.instance).to_s.must_be :==, 'POE and HAWTHORNE'
35
+ Names.parse('Poe and Hawthorne').convert(UpcaseAll.instance).to_s.must_be :==, 'POE and HAWTHORNE'
36
36
  end
37
37
 
38
38
  it "converts LaTeX umlauts" do
@@ -70,7 +70,7 @@ module BibTeX
70
70
  describe "conversions" do
71
71
  before do
72
72
  class Upcase < BibTeX::Filter
73
- def apply (value)
73
+ def apply(value)
74
74
  value.is_a?(::String) ? value.upcase : value
75
75
  end
76
76
  end
@@ -81,7 +81,7 @@ module BibTeX
81
81
  it "converts the value when given a filter instance" do
82
82
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert(Upcase.instance).to_s }
83
83
  end
84
-
84
+
85
85
  it "converts the value when given a filter class" do
86
86
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert(Upcase).to_s }
87
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibtex-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-25 00:00:00.000000000 Z
12
+ date: 2011-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: latex-decode
16
- requirement: &70324808993440 !ruby/object:Gem::Requirement
16
+ requirement: &70212662177440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70324808993440
24
+ version_requirements: *70212662177440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multi_json
27
- requirement: &70324808989740 !ruby/object:Gem::Requirement
27
+ requirement: &70212662176600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70324808989740
35
+ version_requirements: *70212662176600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70324808988600 !ruby/object:Gem::Requirement
38
+ requirement: &70212662175900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.9'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70324808988600
46
+ version_requirements: *70212662175900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: racc
49
- requirement: &70324808987400 !ruby/object:Gem::Requirement
49
+ requirement: &70212662175140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.4'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70324808987400
57
+ version_requirements: *70212662175140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &70324808984640 !ruby/object:Gem::Requirement
60
+ requirement: &70212662174580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.9'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70324808984640
68
+ version_requirements: *70212662174580
69
69
  description: ! "\t\tBibTeX-Ruby is the Rubyist's swiss-army-knife for all things BibTeX.
70
70
  It\n includes a parser for all common BibTeX objects (@string, @preamble,\n @comment
71
71
  and regular entries) and a sophisticated name parser that\n tokenizes correctly