bibtex-ruby 2.3.0 → 2.3.1

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzc1YjdjZmZiYzYyY2UxODIwZWI4YmI2NDAyYmViNWQ1ZTMwNjQyZg==
4
+ OGNlNGUzYjY1OWM2NDAxNDFkMTk0ZjkxMzY0NzQ4ZTRlNWM1YzZmMA==
5
5
  data.tar.gz: !binary |-
6
- NGEwOTAzMzNjMDk2YTkwYTc0ODJiYWQzOTYyYzBiYjNjZjU0NjFkMg==
6
+ YmI4MjQxZWUwYmYzZDZjZDk0YTIxNzg1YjA5NTU2M2RmM2YzMTIzOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmUwOTM3YjhkY2Q1OWFmMGJkMDg1NDc3MjI4NTY0MTYzMzg5MmFhZWZlYmM4
10
- MmFhZmQ5N2ViYWUyNmU2ZTI2NDgyNjFjNGViNTczOWU2ZDE1MzE0OGZkZTI0
11
- OWIxOGZkNDEyODk3YzA3MTNhNzM0ZDIwOTVlNzcyNTAzZTZiZGQ=
9
+ NTc3NGEwZDM0Y2YzYjMwMjM5NDFkMjBkMzdjNzZiN2Y4ZTA5YWUyM2Q0M2Ex
10
+ NGRiYjY2YzViZjAwZjg1YWUwYmNlYWY1OTY4ZWNjNWUwNGFhY2ZlOWY3MmFh
11
+ ZjJjZjczMDBiNWEzYjYxOTA3ZGVjYTUyNjE3MjBmYTdkYWM5MGE=
12
12
  data.tar.gz: !binary |-
13
- MTU2Y2VmZmVkOTZiMzA1NmE2N2M5YzgyOTRlYzY1OGI0MjQ2YWZmM2ZlZDI3
14
- MDFmMTlkY2UzM2EyYWFmN2Q5NjQ1YWFhMmViMjNlMmJlOTlmNzY3ZWVhNDkx
15
- ZWQ5YWRkZjcyZTEzMTQzODkyNTk2ZjdhNmJmZjY5ODY1MGI4ZGY=
13
+ YjVhNjc3YWRjNzgxNWZiNzg4YjdhMTZjY2UxNzZiZjQ0YTJiOTEyMjZkMjk5
14
+ MTY4NjA1NGJiNzA4NDM4ZWQzZDhjMGYyMjRmOWYzNTU2YTI5ZTgwZTk1ODMy
15
+ MzQ0M2JiNjVlOTY5NmNkY2Y2MmI5MTdlMWU5ZGMyNjk4M2EyNDg=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bibtex-ruby (2.3.0)
4
+ bibtex-ruby (2.3.1)
5
5
  latex-decode (>= 0.0.6)
6
6
  multi_json (~> 1.3)
7
7
 
@@ -1,3 +1,8 @@
1
+ 2.3.1 / 2013-07-04
2
+ ==================
3
+
4
+ * Support multiple filters in #convert methods
5
+
1
6
  2.3.0 / 2013-06-04
2
7
  ==================
3
8
 
@@ -7,12 +12,12 @@
7
12
  2.2.2 / 2013-15-01
8
13
  ==================
9
14
 
10
- * Improves Citeproc export #61 #62 (@plessl)
15
+ * Improves CiteProc export #61 #62 (@plessl)
11
16
 
12
17
  2.2.1 / 2013-13-01
13
18
  ==================
14
19
 
15
- * Fixes BibTeX/Citeproc type issue (thanks to @plessl)
20
+ * Fixes BibTeX/CiteProc type issue (thanks to @plessl)
16
21
 
17
22
  2.2.0 / 2012-12-02
18
23
  ==================
@@ -161,12 +161,14 @@ module BibTeX
161
161
  end
162
162
 
163
163
 
164
- # Converts all enties using the given filter. If an optional block is given
164
+ # Converts all enties using the given filter(s). If an optional block is given
165
165
  # the block is used as a condition (the block will be called with each
166
166
  # entry). @see Entry#convert!
167
- def convert (filter)
167
+ def convert(*filters)
168
+ filters = filters.flatten.map { |f| Filters.resolve!(f) }
169
+
168
170
  entries.each_value do |entry|
169
- entry.convert!(filter) if !block_given? || yield(entry)
171
+ entry.convert!(*filters) if !block_given? || yield(entry)
170
172
  end
171
173
 
172
174
  self
@@ -647,18 +647,23 @@ module BibTeX
647
647
  end
648
648
  end
649
649
 
650
- # Returns a duplicate entry with all values converted using the filter.
650
+ # Returns a duplicate entry with all values converted using the filter(s).
651
651
  # If an optional block is given, only those values will be converted where
652
652
  # the block returns true (the block will be called with each key-value pair).
653
653
  #
654
654
  # @see #convert!
655
- def convert(filter)
656
- block_given? ? dup.convert!(filter, &Proc.new) : dup.convert!(filter)
655
+ def convert(*filters)
656
+ block_given? ? dup.convert!(*filters, &Proc.new) : dup.convert!(*filters)
657
657
  end
658
658
 
659
659
  # In-place variant of @see #convert
660
- def convert!(filter)
661
- fields.each_pair { |k,v| !block_given? || yield(k,v) ? v.convert!(filter) : v }
660
+ def convert!(*filters)
661
+ filters = filters.flatten.map { |f| Filters.resolve!(f) }
662
+
663
+ fields.each_pair do |k, v|
664
+ (!block_given? || yield(k, v)) ? v.convert!(*filters) : v
665
+ end
666
+
662
667
  self
663
668
  end
664
669
 
@@ -3,29 +3,29 @@ require 'singleton'
3
3
  module BibTeX
4
4
  class Filter
5
5
  include Singleton
6
-
6
+
7
7
  class << self
8
8
  # Hook called by Ruby if Filter is subclassed
9
9
  def inherited(base)
10
10
  base.class_eval { include Singleton }
11
11
  subclasses << base
12
12
  end
13
-
13
+
14
14
  # Returns a list of all current Filters
15
15
  def subclasses
16
16
  @subclasses ||= []
17
17
  end
18
18
  end
19
-
19
+
20
20
  def apply(value)
21
21
  value
22
22
  end
23
-
23
+
24
24
  alias convert apply
25
25
  alias << apply
26
-
26
+
27
27
  end
28
-
28
+
29
29
  module Filters
30
30
  LOAD_PATH = [File.expand_path('..', __FILE__), 'filters'].join('/').freeze
31
31
 
@@ -33,6 +33,10 @@ module BibTeX
33
33
  require filter
34
34
  end
35
35
 
36
+ def self.resolve!(filter)
37
+ resolve(filter) || raise(ArgumentError, "Failed to load filter #{filter.inspect}")
38
+ end
39
+
36
40
  def self.resolve(filter)
37
41
  case
38
42
  when filter.respond_to?(:apply)
@@ -44,7 +48,7 @@ module BibTeX
44
48
  klass && klass.instance
45
49
  else
46
50
  nil
47
- end
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -260,17 +260,21 @@ module BibTeX
260
260
  end
261
261
  end
262
262
 
263
- def convert(filter)
264
- dup.convert!(filter)
263
+ def convert(*filters)
264
+ dup.convert!(*filters)
265
265
  end
266
266
 
267
- def convert!(filter)
268
- if f = Filters.resolve(filter)
269
- each_pair { |k,v| self[k] = f.apply(v) unless v.nil? }
270
- else
271
- raise ArgumentError, "Failed to load filter #{filter.inspect}"
272
- end
267
+ def convert!(*filters)
268
+ filters.flatten.each do |filter|
269
+
270
+ f = Filters.resolve(filter) ||
271
+ raise(ArgumentError, "Failed to load filter #{filter.inspect}")
273
272
 
273
+ each_pair do |k, v|
274
+ self[k] = f.apply(v) unless v.nil?
275
+ end
276
+ end
277
+
274
278
  self
275
279
  end
276
280
 
@@ -3,17 +3,17 @@
3
3
  #--
4
4
  # BibTeX-Ruby
5
5
  # Copyright (C) 2010-2012 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
9
9
  # the Free Software Foundation, either version 3 of the License, or
10
10
  # (at your option) any later version.
11
- #
11
+ #
12
12
  # This program is distributed in the hope that it will be useful,
13
13
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
15
  # GNU General Public License for more details.
16
- #
16
+ #
17
17
  # You should have received a copy of the GNU General Public License
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  #++
@@ -48,10 +48,10 @@ module BibTeX
48
48
  class Value
49
49
  extend Forwardable
50
50
  include Comparable
51
-
51
+
52
52
  attr_reader :tokens
53
53
  alias to_a tokens
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
57
  def_delegator :@tokens, :each, :each_token
@@ -65,27 +65,27 @@ module BibTeX
65
65
  def self.create(*args)
66
66
  args[0].class < Value && args.size == 1 ? args[0].dup : Value.new(args)
67
67
  end
68
-
68
+
69
69
  def initialize(*arguments)
70
70
  @tokens = []
71
71
  arguments.flatten.compact.each do |argument|
72
72
  add(argument)
73
73
  end
74
74
  end
75
-
75
+
76
76
  def initialize_copy(other)
77
77
  @tokens = other.tokens.dup
78
78
  end
79
-
79
+
80
80
  def merge(other)
81
81
  dup.merge!(other)
82
82
  end
83
-
83
+
84
84
  def merge!(other)
85
85
  other.tokens.each do |token|
86
86
  add token unless include_token?(token)
87
87
  end
88
-
88
+
89
89
  self
90
90
  end
91
91
 
@@ -110,10 +110,10 @@ module BibTeX
110
110
  end
111
111
  self
112
112
  end
113
-
113
+
114
114
  alias << add
115
115
  alias push add
116
-
116
+
117
117
  [:strip!, :upcase!, :downcase!, :sub!, :gsub!, :chop!, :chomp!, :rstrip!].each do |method_id|
118
118
  define_method(method_id) do |*arguments, &block|
119
119
  tokens.each do |part|
@@ -122,7 +122,7 @@ module BibTeX
122
122
  self
123
123
  end
124
124
  end
125
-
125
+
126
126
  def replace(*arguments)
127
127
  return self unless has_symbol?
128
128
  arguments.flatten.each do |argument|
@@ -157,7 +157,7 @@ module BibTeX
157
157
  end
158
158
  self
159
159
  end
160
-
160
+
161
161
  # call-seq:
162
162
  # Value.new('foo').to_s #=> "foo"
163
163
  # Value.new(:foo).to_s #=> "foo"
@@ -189,34 +189,34 @@ module BibTeX
189
189
  def value
190
190
  atomic? ? @tokens[0] : @tokens.map { |v| v.is_a?(::String) ? v.inspect : v }.join(' # ')
191
191
  end
192
-
192
+
193
193
  alias :v :value
194
194
 
195
195
  def inspect
196
196
  "#<#{self.class} #{tokens.map(&:inspect).join(', ')}>"
197
197
  end
198
-
198
+
199
199
  # Returns true if the Value is empty or consists of a single token.
200
200
  def atomic?
201
201
  @tokens.length < 2
202
202
  end
203
-
204
- # Returns true if the value is a BibTeX name value.
203
+
204
+ # Returns true if the value is a BibTeX name value.
205
205
  def name?; false; end
206
-
206
+
207
207
  alias :names? :name?
208
-
208
+
209
209
  def to_name
210
210
  Names.parse(to_s)
211
211
  end
212
-
212
+
213
213
  alias to_names to_name
214
214
 
215
- # Returns true if the Value's content is a date.
215
+ # Returns true if the Value's content is a date.
216
216
  def date?
217
217
  !to_date.nil?
218
218
  end
219
-
219
+
220
220
  # Returns the string as a date.
221
221
  def to_date
222
222
  require 'date'
@@ -224,44 +224,43 @@ module BibTeX
224
224
  rescue
225
225
  nil
226
226
  end
227
-
227
+
228
228
  # Returns true if the Value's content is numeric.
229
229
  def numeric?
230
230
  to_s =~ /^\s*[+-]?\d+[\/\.]?\d*\s*$/
231
231
  end
232
-
232
+
233
233
  def to_citeproc (options = {})
234
234
  to_s(options)
235
235
  end
236
-
236
+
237
237
  # Returns true if the Value contains at least one symbol.
238
238
  def symbol?
239
239
  tokens.detect { |v| v.is_a?(Symbol) }
240
240
  end
241
-
241
+
242
242
  alias has_symbol? symbol?
243
-
243
+
244
244
  # Returns all symbols contained in the Value.
245
245
  def symbols
246
246
  tokens.select { |v| v.is_a?(Symbol) }
247
247
  end
248
-
249
- # Returns a new Value with all string values converted according to the given filter.
250
- def convert (filter)
251
- dup.convert!(filter)
248
+
249
+ # Returns a new Value with all string values converted according to the given filter(s).
250
+ def convert (*filters)
251
+ dup.convert!(*filters)
252
252
  end
253
-
254
- # Converts all string values according to the given filter.
255
- def convert! (filter)
256
- if f = Filters.resolve(filter)
253
+
254
+ # Converts all string values according to the given filter(s).
255
+ def convert! (*filters)
256
+ filters.flatten.each do |filter|
257
+ f = Filters.resolve!(filter)
257
258
  tokens.map! { |t| f.apply(t) }
258
- else
259
- raise ArgumentError, "Failed to load filter #{filter.inspect}"
260
259
  end
261
-
260
+
262
261
  self
263
262
  end
264
-
263
+
265
264
  def method_missing (name, *args)
266
265
  case
267
266
  when name.to_s =~ /^(?:convert|from)_([a-z]+)(!)?$/
@@ -270,15 +269,15 @@ module BibTeX
270
269
  super
271
270
  end
272
271
  end
273
-
272
+
274
273
  def respond_to? (method)
275
274
  method =~ /^(?:convert|from)_([a-z]+)(!)?$/ || super
276
275
  end
277
-
276
+
278
277
  def <=> (other)
279
278
  to_s <=> other.to_s
280
279
  end
281
-
280
+
282
281
  end
283
282
 
284
283
  end
@@ -20,7 +20,7 @@ module BibTeX
20
20
  module Version
21
21
  MAJOR = 2
22
22
  MINOR = 3
23
- PATCH = 0
23
+ PATCH = 1
24
24
  BUILD = nil
25
25
 
26
26
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
@@ -269,21 +269,30 @@ module BibTeX
269
269
  assert_equal 'Melville', e['author'][0]['family']
270
270
  end
271
271
 
272
- describe 'given a filter' do
272
+ describe 'given a filter object or a filter name' do
273
273
  before do
274
274
  @filter = Object.new
275
275
  def @filter.apply (value); value.is_a?(::String) ? value.upcase : value; end
276
+
277
+ class SuffixB < BibTeX::Filter
278
+ def apply(value)
279
+ value.is_a?(::String) ? "#{value}b" : value
280
+ end
281
+ end
276
282
  end
277
283
 
278
284
  it 'supports arbitrary conversion' do
279
- e = @entry.convert(@filter)
280
- assert_equal 'MOBY DICK', e.title
281
- assert_equal 'Moby Dick', @entry.title
285
+ @entry.convert(@filter).title.must_equal 'MOBY DICK'
286
+ @entry.convert(:suffixb).title.must_equal 'Moby Dickb'
287
+ end
288
+
289
+ it 'supports multiple filters' do
290
+ @entry.convert(@filter, :suffixb).title.must_equal 'MOBY DICKb'
291
+ @entry.convert(:suffixb, @filter).title.must_equal 'MOBY DICKB'
282
292
  end
283
293
 
284
294
  it 'supports arbitrary in-place conversion' do
285
- @entry.convert!(@filter)
286
- assert_equal 'MOBY DICK', @entry.title
295
+ @entry.convert!(@filter).title.must_equal 'MOBY DICK'
287
296
  end
288
297
 
289
298
  it 'supports conditional arbitrary in-place conversion' do
@@ -98,6 +98,13 @@ module BibTeX
98
98
  value.is_a?(::String) ? value.upcase : value
99
99
  end
100
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
+
101
108
  @values = [Value.new('foo'), Value.new('foo', :bar)]
102
109
  end
103
110
 
@@ -113,6 +120,12 @@ module BibTeX
113
120
  it "converts the value when given the name of a filter" do
114
121
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert(:upcase).to_s }
115
122
  assert_equal ['FOO', '"FOO" # bar'], @values.map { |v| v.convert('upcase').to_s }
123
+ assert_equal ['fooa', '"fooa" # bar'], @values.map { |v| v.convert('suffixa').to_s }
124
+ end
125
+
126
+ it "applies multiple filters in the order passed" do
127
+ @values.map { |v| v.convert(:upcase, :suffixa).to_s }.must_equal ['FOOa', '"FOOa" # bar']
128
+ @values.map { |v| v.convert(:suffixa, :upcase).to_s }.must_equal ['FOOA', '"FOOA" # bar']
116
129
  end
117
130
 
118
131
  it "converts the value when using a ghost method" do
@@ -128,6 +141,16 @@ module BibTeX
128
141
  @values.each { |v| v.convert_upcase }
129
142
  assert_equal ['foo', '"foo" # bar'], @values.map(&:to_s)
130
143
  end
144
+
145
+ it "raises argument error when a filter cannot be resolved" do
146
+ assert_raises ArgumentError do
147
+ @values[0].convert(:foo)
148
+ end
149
+
150
+ assert_raises ArgumentError do
151
+ @values[0].convert(:upcase, :foo)
152
+ end
153
+ end
131
154
  end
132
155
 
133
156
  describe "#convert!" do
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: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-06 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: latex-decode