bibtex-ruby 5.1.1 → 5.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1220f03462fd20dc2547ad2d690860f971e3ae6d73374d76071e78d62438eee
4
- data.tar.gz: c518a5179f6325c0ac3a2cba62107e3e6be6b7fe8c40a5b0c02f8ef38dea56fe
3
+ metadata.gz: 5a1f7a49db70b1dcaa1330aeacd9e1ce43fd79a0904f7c4be0c220e84e331528
4
+ data.tar.gz: 536ecca150ff1889fca9976515f0226ac17ded8e0a3cd27b41b3c1cbc75baa0e
5
5
  SHA512:
6
- metadata.gz: d0d1816bd6913c7723b8ac6d77d42ea4e87cd1a76451c8075a890e802846402b4c27de8293ff842702a210305758279465da47541798b6cd20359a0fa0691e4e
7
- data.tar.gz: 67dba827e0ea514f6182fd82fb489034a7551b4704061539e1e316094e32be8ab7a31ac36753f299f96031543bf4e390c88dfacda4b472242e366daac0a9ef93
6
+ metadata.gz: 57bfe6e85f4e7d5e88855d6637bc59f6f062d09dd72cc9c13b8ab7731737303dfe5531a33245b8dd70a33e6eed2ebcf8bf73be9da103ee896a6f16443067679c
7
+ data.tar.gz: ccb43ac768278194cdecd9f6c649c67b8d74795a30bdce34c39b117c5677d1745d1efe52411b12569b188f74d513175f77e5bb104d751e5c58004c8c6953b87f
data/Gemfile CHANGED
@@ -27,13 +27,13 @@ group :profile do
27
27
  end
28
28
 
29
29
  group :coverage do
30
- gem 'coveralls', '~>0.8', require: false
30
+ gem 'coveralls', require: false
31
31
  gem 'simplecov', require: false, platforms: [:ruby]
32
32
  end
33
33
 
34
34
  group :development do
35
35
  gem 'iconv', platforms: [:ruby]
36
+ gem 'racc'
36
37
  gem 'rake'
37
- gem 'rubocop', require: false
38
38
  gem 'yard'
39
39
  end
data/Rakefile CHANGED
@@ -11,7 +11,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), './lib'))
11
11
 
12
12
  require 'rake/clean'
13
13
  require 'rake/testtask'
14
- require 'rubocop/rake_task'
15
14
 
16
15
  require 'bibtex/version'
17
16
 
@@ -44,9 +43,7 @@ rescue LoadError
44
43
  # ignore
45
44
  end
46
45
 
47
- RuboCop::RakeTask.new
48
-
49
- task default: %i[test features rubocop]
46
+ task default: %i[test features]
50
47
 
51
48
  desc 'Generates the BibTeX parser'
52
49
  task racc: ['lib/bibtex/parser.rb', 'lib/bibtex/name_parser.rb']
@@ -117,43 +117,6 @@ module BibTeX
117
117
  self
118
118
  end
119
119
 
120
- # Generate accessors for required fields (#52)
121
- REQUIRED_FIELDS.values.flatten.uniq.each do |name|
122
- unless method_defined? name
123
- define_method(name) do
124
- get name
125
- end
126
- end
127
-
128
- writer = "#{name}="
129
-
130
- next if method_defined? writer
131
-
132
- define_method(writer) do |value|
133
- add name, value
134
- end
135
- end
136
-
137
- # Generate author, editor and translator accessors
138
- NAME_FIELDS.each do |contributor|
139
- unless method_defined? contributor
140
- define_method(contributor) do
141
- get contributor
142
- end
143
- end
144
-
145
- writer = "#{contributor}="
146
-
147
- unless method_defined? writer
148
- define_method(writer) do |value|
149
- add contributor, value
150
- end
151
- end
152
-
153
- alias_method "#{contributor}s", contributor
154
- alias_method "#{contributor}s=", writer
155
- end
156
-
157
120
  # call-seq:
158
121
  # entry.each { |key, value| block } -> entry
159
122
  # entry.each_pair { |key, value| block } -> entry
@@ -216,7 +179,7 @@ module BibTeX
216
179
  end
217
180
 
218
181
  def has_type?(type)
219
- type.to_s.match(/^(?:entry|\*)$/i) || @type == type.to_sym || super
182
+ type.to_s.match(/^(?:entry|\*)$/i) || @type.casecmp?(type.to_sym) || super
220
183
  end
221
184
 
222
185
  alias type? has_type?
@@ -669,6 +632,44 @@ module BibTeX
669
632
  fields[:date].to_s[/\d{4}/]
670
633
  end
671
634
 
635
+ # Generate accessors for required fields (#52)
636
+ REQUIRED_FIELDS.values.flatten.uniq.each do |name|
637
+ unless method_defined? name
638
+ define_method(name) do
639
+ get name
640
+ end
641
+ end
642
+
643
+ writer = "#{name}="
644
+
645
+ next if method_defined? writer
646
+
647
+ define_method(writer) do |value|
648
+ add name, value
649
+ end
650
+ end
651
+
652
+ # Generate author, editor and translator accessors
653
+ NAME_FIELDS.each do |contributor|
654
+ unless method_defined? contributor
655
+ define_method(contributor) do
656
+ get contributor
657
+ end
658
+ end
659
+
660
+ writer = "#{contributor}="
661
+
662
+ unless method_defined? writer
663
+ define_method(writer) do |value|
664
+ add contributor, value
665
+ end
666
+ end
667
+
668
+ alias_method "#{contributor}s", contributor
669
+ alias_method "#{contributor}s=", writer
670
+ end
671
+
672
+
672
673
  private
673
674
 
674
675
  # Returns a default key for this entry.
@@ -20,6 +20,7 @@ class BibTeX::Entry::CiteProcConverter
20
20
  organization publisher
21
21
  howpublished publisher
22
22
  type genre
23
+ urldate accessed
23
24
  ].map(&:intern)]).freeze
24
25
 
25
26
  CSL_FIELDS = %w[
@@ -56,6 +57,7 @@ class BibTeX::Entry::CiteProcConverter
56
57
 
57
58
  def initialize(bibtex, options = {})
58
59
  @bibtex = bibtex
60
+ @hash = {}
59
61
  @options = { quotes: [] }.merge(options)
60
62
  end
61
63
 
@@ -122,6 +124,21 @@ class BibTeX::Entry::CiteProcConverter
122
124
  end
123
125
  end
124
126
 
127
+ def accessed
128
+ return unless hash.key? 'accessed'
129
+
130
+ hash['accessed'] =
131
+ case hash['accessed']
132
+ when %r{^[\d/\s-]+$}
133
+ {
134
+ 'date-parts' =>
135
+ hash['accessed'].split('/').map { |pt| pt.split('-').map(&:to_i) }
136
+ }
137
+ else
138
+ { 'literal' => hash['accessed'] }
139
+ end
140
+ end
141
+
125
142
  def key
126
143
  hash['id'] = bibtex.key.to_s
127
144
  end
@@ -141,21 +158,26 @@ class BibTeX::Entry::CiteProcConverter
141
158
 
142
159
  private
143
160
 
144
- attr_reader :bibtex, :options
161
+ attr_reader :bibtex, :options, :hash
145
162
 
146
163
  def convert(key, value)
147
164
  return if BibTeX::Entry::DATE_FIELDS.include?(key)
165
+ return include_url(value) if howpublished_with_url?(key, value)
148
166
 
149
- cp_key = CSL_FILTER[key].to_s
167
+ citeproc_key = CSL_FILTER[key].to_s
150
168
 
151
- if hash.key?(cp_key)
169
+ if hash.key?(citeproc_key)
152
170
  hash[key] = value.to_citeproc(options)
153
171
  else
154
- hash[cp_key] = value.to_citeproc(options)
172
+ hash[citeproc_key] = value.to_citeproc(options)
155
173
  end
156
174
  end
157
175
 
158
- def hash
159
- @hash ||= {}
176
+ def howpublished_with_url?(key, value)
177
+ key == :howpublished && value.include?('url')
178
+ end
179
+
180
+ def include_url(value)
181
+ hash['URL'] = value.to_s[/url{?([^}]*)/, 1]
160
182
  end
161
183
  end
@@ -49,9 +49,9 @@ module BibTeX
49
49
  alias to_a tokens
50
50
 
51
51
  def_delegators :to_s, :=~, :===,
52
- *String.instance_methods(false).reject do |m|
53
- m =~ /^\W|^(length|dup|replace|to_s|inspect)$|!$/
54
- end
52
+ *String.instance_methods(false).reject { |m|
53
+ m =~ /^\W|^(length|dup|replace|to_s|to_i|inspect)$|!$/
54
+ }
55
55
 
56
56
  def_delegators :@tokens, :[], :length
57
57
  def_delegator :@tokens, :each, :each_token
@@ -180,7 +180,12 @@ module BibTeX
180
180
  # If the option :filter is given, the Value will be converted using
181
181
  # the filter(s) specified.
182
182
  def to_s(options = {})
183
- return convert(options.delete(:filter)).to_s(options) if options.key?(:filter)
183
+ if options.key?(:filter)
184
+ return convert(options[:filter]).to_s(
185
+ options.reject { |k,| k == :filter || (k == :quotes && (!atomic? || symbol?)) }
186
+ )
187
+ end
188
+
184
189
  return value.to_s unless options.key?(:quotes) && atomic? && !symbol?
185
190
 
186
191
  q = Array(options[:quotes])
@@ -20,7 +20,7 @@ module BibTeX
20
20
  module Version
21
21
  MAJOR = 5
22
22
  MINOR = 1
23
- PATCH = 1
23
+ PATCH = 6
24
24
  BUILD = nil
25
25
 
26
26
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
@@ -31,7 +31,8 @@ module BibTeX
31
31
  @bib = Bibliography.parse <<-END
32
32
  @book{a, editor = "A", title = "A"}
33
33
  @incollection{a1, crossref = "a"}
34
- @incollection{b1, crossref = "b"}
34
+ @incollection{b1, crossref = "b2"}
35
+ @book{b, author = "B", title = "B", date = "2020", urldate = "2020"}
35
36
  END
36
37
  end
37
38
 
@@ -124,6 +125,10 @@ module BibTeX
124
125
  it 'includes inherited values' do
125
126
  @bib['a1'].to_citeproc['container-title'].must_be :==, @bib['a'].title.to_s
126
127
  end
128
+
129
+ it 'converts urldate' do
130
+ @bib['b'].to_citeproc['accessed'].must_be :==, 'date-parts' => [[2020]]
131
+ end
127
132
  end
128
133
 
129
134
  describe '#save_inherited_fields' do
@@ -433,7 +438,7 @@ module BibTeX
433
438
  end
434
439
  end
435
440
 
436
- describe 'citeproc export' do
441
+ describe '#to_citeproc' do
437
442
  before do
438
443
  @entry = Entry.new do |e|
439
444
  e.type = :book
@@ -450,6 +455,58 @@ module BibTeX
450
455
  it 'should accept option to use non-dropping-particle' do
451
456
  assert_equal 'van', @entry.to_citeproc(particle: 'non-dropping-particle')['author'][0]['non-dropping-particle']
452
457
  end
458
+
459
+ describe 'howpublished' do
460
+ it 'converts to "URL" when there is a url (without filters)' do
461
+ bibtex = <<-END
462
+ @book{noauthor_2017-xx,
463
+ title = "Google",
464
+ howpublished = "\\url{http://www.google.com/}"
465
+ }
466
+ END
467
+ bibliography = Bibliography.parse(bibtex)
468
+
469
+ citeproc = bibliography.to_citeproc
470
+
471
+ assert_equal('http://www.google.com/', citeproc[0]['URL'])
472
+ assert_nil(citeproc[0]['publisher'])
473
+ end
474
+
475
+ it 'converts to "URL" when there is a url (with latex)' do
476
+ bibtex = <<-END
477
+ @book{noauthor_2017-xx,
478
+ title = "Google",
479
+ howpublished = "\\url{http://www.google.com/}"
480
+ }
481
+ END
482
+ bibliography = Bibliography.parse(bibtex, filter: :latex)
483
+
484
+ citeproc = bibliography.to_citeproc
485
+
486
+ assert_equal('http://www.google.com/', citeproc[0]['URL'])
487
+ end
488
+ end
489
+ end
490
+
491
+ describe '#to_s' do
492
+ before do
493
+ @bib = Bibliography.parse(<<-BIBINPUT, parse_months: false)
494
+ @misc{foo,
495
+ title = {A
496
+ title},
497
+ series = {A
498
+ series},
499
+ month = dec
500
+ }
501
+ BIBINPUT
502
+ end
503
+ it 'applies filters when converting to strings' do
504
+ assert_equal "@misc{foo,\n"\
505
+ " title = {A title},\n"\
506
+ " series = {A series},\n"\
507
+ " month = dec\n"\
508
+ "}\n", @bib['foo'].to_s(filter: :linebreaks)
509
+ end
453
510
  end
454
511
 
455
512
  def test_simple
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: 5.1.1
4
+ version: 5.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: latex-decode
@@ -128,7 +128,7 @@ homepage: http://inukshuk.github.com/bibtex-ruby
128
128
  licenses:
129
129
  - GPL-3.0
130
130
  metadata: {}
131
- post_install_message:
131
+ post_install_message:
132
132
  rdoc_options: []
133
133
  require_paths:
134
134
  - lib
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubygems_version: 3.1.2
147
- signing_key:
147
+ signing_key:
148
148
  specification_version: 4
149
149
  summary: A BibTeX parser, converter and API for Ruby.
150
150
  test_files:
@@ -157,8 +157,8 @@ test_files:
157
157
  - test/bibtex/test_string.rb
158
158
  - test/bibtex/test_utilities.rb
159
159
  - test/bibtex/test_value.rb
160
- - test/bibtex/test_entry.rb
161
160
  - test/bibtex/test_filters.rb
162
161
  - test/bibtex/test_bibliography.rb
162
+ - test/bibtex/test_entry.rb
163
163
  - test/test_bibtex.rb
164
164
  - test/test_export.rb