bibtex-ruby 4.4.7 → 5.0.0

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.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +23 -24
  3. data/History.txt +4 -0
  4. data/Rakefile +23 -25
  5. data/bibtex-ruby.gemspec +1 -1
  6. data/examples/bib2html.rb +5 -6
  7. data/examples/bib2yaml.rb +2 -2
  8. data/features/step_definitions/bibtex_steps.rb +3 -6
  9. data/features/step_definitions/name_steps.rb +1 -2
  10. data/lib/bibtex.rb +11 -13
  11. data/lib/bibtex/bibliography.rb +45 -58
  12. data/lib/bibtex/compatibility.rb +3 -5
  13. data/lib/bibtex/elements.rb +49 -42
  14. data/lib/bibtex/entry.rb +80 -84
  15. data/lib/bibtex/entry/citeproc_converter.rb +47 -52
  16. data/lib/bibtex/entry/rdf_converter.rb +97 -63
  17. data/lib/bibtex/error.rb +10 -11
  18. data/lib/bibtex/extensions.rb +2 -5
  19. data/lib/bibtex/filters.rb +4 -9
  20. data/lib/bibtex/filters/latex.rb +0 -2
  21. data/lib/bibtex/filters/linebreaks.rb +0 -2
  22. data/lib/bibtex/lexer.rb +81 -81
  23. data/lib/bibtex/names.rb +24 -28
  24. data/lib/bibtex/replaceable.rb +15 -17
  25. data/lib/bibtex/utilities.rb +5 -10
  26. data/lib/bibtex/value.rb +28 -34
  27. data/lib/bibtex/version.rb +6 -6
  28. data/test/benchmark.rb +20 -22
  29. data/test/bibtex/entry/test_rdf_converter.rb +3 -5
  30. data/test/bibtex/test_bibliography.rb +22 -35
  31. data/test/bibtex/test_elements.rb +7 -15
  32. data/test/bibtex/test_entry.rb +78 -87
  33. data/test/bibtex/test_filters.rb +8 -7
  34. data/test/bibtex/test_lexer.rb +10 -13
  35. data/test/bibtex/test_name_parser.rb +6 -9
  36. data/test/bibtex/test_names.rb +50 -55
  37. data/test/bibtex/test_parser.rb +30 -34
  38. data/test/bibtex/test_string.rb +8 -9
  39. data/test/bibtex/test_utilities.rb +6 -9
  40. data/test/bibtex/test_value.rb +41 -43
  41. data/test/helper.rb +3 -6
  42. data/test/macruby.rb +12 -13
  43. data/test/profile.rb +16 -16
  44. data/test/test_bibtex.rb +10 -15
  45. data/test/test_export.rb +5 -13
  46. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62c4e2816fb0d45f48ff04f0ef762dcc1ed6fce5f7523ce86390bf5426a80806
4
- data.tar.gz: b8158882899c29a86514ba842272a7587340648c08a37710ed66c0eadde522b0
3
+ metadata.gz: 1f116d02973cd3647ce69ab85bee28bfa5a361cb8eadc006905c4688839895b8
4
+ data.tar.gz: 8770d47027cf981318066773c7f7656317e69c3e47c81422429e38b830ac5ce3
5
5
  SHA512:
6
- metadata.gz: d7598c33f7b1f60a1fa1d9bd313f918c9a9151c72b4aa14c13cfb4ad70e58dfda3413b7ae40836d0ebfb470fe7854721a65f03de2b5492e2ac3f16be7f8ef39b
7
- data.tar.gz: 39ffcdc7195f0d041703a6cddfc3924f62a7ef439cfeaa04b7d5de98229daa3c6a58c5ec44a05b1bce90f6c390f1f825c6064368a8442f0fca04bf329f5dc2c6
6
+ metadata.gz: d5123a130e935e4710b6d907e9af2a9fe8e6e56f836ffd41acebc546faad2bd9f448508da7286d403f1ee5276737065fb85718609b680f32095dfa5ef6fdea43
7
+ data.tar.gz: c088b05105b9371a0578ebb7502518b974103168b59bcb9d3172c1a166b9f63e100eedf003aaf1d2772086e8c00df9581555f98c5f38913a006f4a2c7e45528d
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'json', '~>1.8', :platforms => [:mri_18, :jruby, :rbx]
4
+ gem 'json', '~>1.8', platforms: %i[mri_18 jruby rbx]
5
5
 
6
6
  if RUBY_VERSION >= '2.0'
7
7
  gem 'rdf', '~>2.0.0'
@@ -10,57 +10,56 @@ else
10
10
  gem 'rdf', '~>1.1'
11
11
  end
12
12
 
13
- gem 'rubysl', '~>2.0', :platforms => :rbx
13
+ gem 'rubysl', '~>2.0', platforms: :rbx
14
14
 
15
15
  group :debug do
16
16
  if RUBY_VERSION >= '2.0'
17
- gem 'byebug', :require => false, :platforms => :mri
17
+ gem 'byebug', require: false, platforms: :mri
18
18
  else
19
- gem 'debugger', :require => false, :platforms => :mri
19
+ gem 'debugger', require: false, platforms: :mri
20
20
  end
21
21
 
22
- gem 'ruby-debug', :require => false, :platforms => :jruby
22
+ gem 'ruby-debug', require: false, platforms: :jruby
23
23
 
24
- gem 'rubinius-debugger', :require => false, :platforms => :rbx
25
- gem 'rubinius-compiler', :require => false, :platforms => :rbx
24
+ gem 'rubinius-compiler', require: false, platforms: :rbx
25
+ gem 'rubinius-debugger', require: false, platforms: :rbx
26
26
  end
27
27
 
28
28
  group :test do
29
- gem 'minitest', '~>4.7', :require => false
30
- gem 'rubysl-test-unit', '~>2.0', :platforms => :rbx
31
- gem 'minitest-ansi'
32
29
  gem 'cucumber', '~>1.3'
33
- gem 'unicode', '~>0.4', :platforms => [:rbx, :mswin, :mingw, :mri]
30
+ gem 'minitest', '~>4.7', require: false
31
+ gem 'minitest-ansi'
32
+ gem 'rubysl-test-unit', '~>2.0', platforms: :rbx
33
+ gem 'unicode', '~>0.4', platforms: %i[rbx mswin mingw mri]
34
34
  end
35
35
 
36
36
  group :extra do
37
- if RUBY_PLATFORM =~ /darwin/i
38
- gem 'rb-fsevent', :require => false
39
- end
37
+ gem 'rb-fsevent', require: false if RUBY_PLATFORM =~ /darwin/i
40
38
 
41
- gem 'guard-minitest', :platforms => [:ruby]
42
- gem 'guard-cucumber', :platforms => [:ruby]
43
- gem 'redcarpet', :platforms => [:ruby]
39
+ gem 'guard-cucumber', platforms: [:ruby]
40
+ gem 'guard-minitest', platforms: [:ruby]
41
+ gem 'redcarpet', platforms: [:ruby]
44
42
  end
45
43
 
46
44
  group :profile do
47
- gem 'ruby-prof', '~>0.14', :platforms => [:mri]
48
- gem 'gnuplot', '~>2.4', :platforms => [:mri]
45
+ gem 'gnuplot', '~>2.4', platforms: [:mri]
46
+ gem 'ruby-prof', '~>0.14', platforms: [:mri]
49
47
  end
50
48
 
51
49
  group :coverage do
52
- gem 'simplecov', '~>0.8', :require => false, :platforms => [:ruby]
53
- gem 'rubinius-coverage', :require => false, :platforms => :rbx
54
- gem 'coveralls', '~>0.7', :require => false
50
+ gem 'coveralls', '~>0.7', require: false
51
+ gem 'rubinius-coverage', require: false, platforms: :rbx
52
+ gem 'simplecov', '~>0.8', require: false, platforms: [:ruby]
55
53
  end
56
54
 
57
55
  group :development do
56
+ gem 'iconv', platforms: [:ruby]
58
57
  gem 'rake'
58
+ gem 'rubocop', '~> 0.71.0', require: false
59
59
  gem 'yard'
60
- gem 'iconv', :platforms => [:ruby]
61
60
  end
62
61
 
63
62
  group :travis do
64
63
  # Gem is required at runtime for RBX!
65
- gem 'racc', :platforms => [:ruby]
64
+ gem 'racc', platforms: [:ruby]
66
65
  end
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ 5.0.0 / 2019-06-12
2
+ ==================
3
+ * Dropped support for Ruby < 2.3
4
+
1
5
  4.2.0 / 2015-02-02
2
6
  ==================
3
7
  * Fixed queries being whitespace sensitive
data/Rakefile CHANGED
@@ -1,19 +1,17 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bundler'
4
2
  begin
5
3
  Bundler.setup
6
4
  rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts "Run `bundle install` to install missing gems"
5
+ warn e.message
6
+ warn 'Run `bundle install` to install missing gems'
9
7
  exit e.status_code
10
8
  end
11
9
 
12
- $:.unshift(File.join(File.dirname(__FILE__), './lib'))
13
-
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), './lib'))
14
11
 
15
12
  require 'rake/clean'
16
13
  require 'rake/testtask'
14
+ require 'rubocop/rake_task'
17
15
 
18
16
  require 'bibtex/version'
19
17
 
@@ -29,7 +27,7 @@ end
29
27
  begin
30
28
  require 'cucumber/rake/task'
31
29
  Cucumber::Rake::Task.new(:features) do |t|
32
- t.cucumber_opts = "--format progress"
30
+ t.cucumber_opts = '--format progress'
33
31
  end
34
32
  rescue LoadError
35
33
  desc 'Cucumber rake task not available'
@@ -41,17 +39,19 @@ end
41
39
  begin
42
40
  require 'coveralls/rake/task'
43
41
  Coveralls::RakeTask.new
44
- task :test_with_coveralls => [:test, :features, 'coveralls:push']
42
+ task test_with_coveralls: [:test, :features, 'coveralls:push']
45
43
  rescue LoadError
46
44
  # ignore
47
45
  end
48
46
 
49
- task :default => [:test, :features]
47
+ RuboCop::RakeTask.new
48
+
49
+ task default: %i[test features rubocop]
50
50
 
51
51
  desc 'Generates the BibTeX parser'
52
- task :racc => ['lib/bibtex/parser.rb','lib/bibtex/name_parser.rb']
52
+ task racc: ['lib/bibtex/parser.rb', 'lib/bibtex/name_parser.rb']
53
53
 
54
- task :test => ['racc','test_task']
54
+ task test: %w[racc test_task]
55
55
 
56
56
  file 'lib/bibtex/parser.output' => ['lib/bibtex/parser.rb']
57
57
  file 'lib/bibtex/parser.rb' => ['lib/bibtex/bibtex.y'] do
@@ -65,7 +65,7 @@ file 'lib/bibtex/name_parser.rb' => ['lib/bibtex/names.y'] do
65
65
  end
66
66
 
67
67
  desc 'Run an IRB session with BibTeX-Ruby loaded'
68
- task :console, [:script] do |t,args|
68
+ task :console, [:script] do |_t, args|
69
69
  ARGV.clear
70
70
 
71
71
  require 'irb'
@@ -82,37 +82,35 @@ task :check_warnings do
82
82
  puts BibTeX::Version::STRING
83
83
  end
84
84
 
85
-
86
85
  desc 'Runs the benchmarks (and plots the results)'
87
- task :benchmark => ['racc'] do
88
- require File.expand_path('../test/benchmark.rb', __FILE__)
86
+ task benchmark: ['racc'] do
87
+ require File.expand_path('test/benchmark.rb', __dir__)
89
88
  end
90
- task :bm => ['benchmark']
89
+ task bm: ['benchmark']
91
90
 
92
91
  desc 'Runs the profiler'
93
- task :profile => ['racc'] do
94
- require File.expand_path('../test/profile.rb', __FILE__)
92
+ task profile: ['racc'] do
93
+ require File.expand_path('test/profile.rb', __dir__)
95
94
  end
96
95
 
97
-
98
96
  desc 'Updates the Manifest file'
99
- task :manifest => ['clean', 'racc'] do
97
+ task manifest: %w[clean racc] do
100
98
  m = File.open('Manifest', 'w')
101
- m.print FileList['**/*'].reject{ |f|
99
+ m.print FileList['**/*'].reject { |f|
102
100
  f.start_with?('coverage') || f =~ /(rbc|swp|~|lock)$/
103
101
  }.join("\n")
104
102
  m.close
105
103
  end
106
104
 
107
105
  desc 'Builds the gem file'
108
- task :build => ['manifest'] do
106
+ task build: ['manifest'] do
109
107
  system 'gem build bibtex-ruby.gemspec'
110
108
  end
111
109
 
112
110
  desc 'Pushes the gem file to rubygems.org'
113
- task :release => ['build'] do
114
- system %Q{git tag "#{BibTeX::Version::STRING}"}
115
- system "git push --tags"
111
+ task release: ['build'] do
112
+ system %(git tag "#{BibTeX::Version::STRING}")
113
+ system 'git push --tags'
116
114
  system "gem push bibtex-ruby-#{BibTeX::Version::STRING}.gem"
117
115
  end
118
116
 
data/bibtex-ruby.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  lib = File.expand_path('../lib/', __FILE__)
3
2
  $:.unshift lib unless $:.include?(lib)
4
3
 
@@ -8,6 +7,7 @@ Gem::Specification.new do |s|
8
7
  s.name = 'bibtex-ruby'
9
8
  s.version = BibTeX::Version::STRING.dup
10
9
  s.platform = Gem::Platform::RUBY
10
+ s.required_ruby_version = '>= 2.3.0'
11
11
  s.authors = ['Sylvester Keil']
12
12
  s.email = ['sylvester@keil.or.at']
13
13
  s.homepage = 'http://inukshuk.github.com/bibtex-ruby'
data/examples/bib2html.rb CHANGED
@@ -10,28 +10,27 @@ rescue LoadError
10
10
  end
11
11
 
12
12
  # Open a bibliography file
13
- bib = BibTeX.open File.expand_path('../markdown.bib',__FILE__),
14
- :include => [:meta_content]
13
+ bib = BibTeX.open File.expand_path('markdown.bib', __dir__),
14
+ include: [:meta_content]
15
15
 
16
16
  # Replaces all strings in the Bibliography and then
17
17
  # converts each BibTeX entries to a string using Chicago style
18
18
  # (all other elements are mapped to simple strings)
19
19
  bib.replace
20
20
 
21
- cp = CiteProc::Processor.new :style => 'apa',
22
- :format => 'html', :locale => 'en'
21
+ cp = CiteProc::Processor.new style: 'apa',
22
+ format: 'html', locale: 'en'
23
23
 
24
24
  cp.import bib.to_citeproc
25
25
 
26
26
  content = bib['@entry, @meta_content'].map do |e|
27
27
  if e.entry?
28
- cp.render :bibliography, :id => e.key
28
+ cp.render :bibliography, id: e.key
29
29
  else
30
30
  e.to_s
31
31
  end
32
32
  end
33
33
 
34
-
35
34
  begin
36
35
  require 'redcarpet'
37
36
  rescue LoadError
data/examples/bib2yaml.rb CHANGED
@@ -4,8 +4,8 @@ require 'rubygems'
4
4
  require 'bibtex'
5
5
  require 'yaml'
6
6
 
7
- if ARGV.length < 1
8
- puts "Usage: #{$0} <bib> [<yml>]"
7
+ if ARGV.empty?
8
+ puts "Usage: #{$PROGRAM_NAME} <bib> [<yml>]"
9
9
  else
10
10
  out = ARGV.length == 2 ? File.open(ARGV[1], 'w') : STDOUT
11
11
  out.puts BibTeX.open(ARGV[0]).to_yaml
@@ -14,7 +14,7 @@ When /^I search for :(.+)$/ do |query|
14
14
  @result = @bibliography.query(query.to_sym)
15
15
  end
16
16
 
17
- When /^I search for \/(.+)\/$/ do |query|
17
+ When %r{^I search for /(.+)/$} do |query|
18
18
  @result = @bibliography.query(Regexp.new(query))
19
19
  end
20
20
 
@@ -50,7 +50,6 @@ When /^I create entries with these elements:$/ do |table|
50
50
  end
51
51
  end
52
52
 
53
-
54
53
  Then /^my bibliography should contain the following objects:$/ do |table|
55
54
  @bibliography.each_with_index do |object, index|
56
55
  table.hashes[index].each_pair do |key, value|
@@ -69,7 +68,7 @@ end
69
68
 
70
69
  Then /^my bibliography should contain the following numbers of elements:$/ do |table|
71
70
  counts = table.hashes.first
72
- counts[[]] = counts.delete('total') if counts.has_key?('total')
71
+ counts[[]] = counts.delete('total') if counts.key?('total')
73
72
  counts.each_pair do |type, length|
74
73
  assert_equal length.to_i, @bibliography.find_by_type(type).length
75
74
  end
@@ -83,12 +82,11 @@ Then /^my bibliography should contain an entry with an? (?:key|id) like "([^"]*)
83
82
  pattern = Regexp.compile key
84
83
  refute_nil @bibliography.detect { |e| e.key.to_s =~ pattern }
85
84
  end
86
- Then /^my bibliography should contain an entry with (?:key|id) "([^"]*)" and a?n? (\w+) value of "([^"]*)"$/ do |key,field,value|
85
+ Then /^my bibliography should contain an entry with (?:key|id) "([^"]*)" and a?n? (\w+) value of "([^"]*)"$/ do |key, field, value|
87
86
  refute_nil @bibliography[key.to_s]
88
87
  assert_equal value, @bibliography[key.to_s][field.downcase.to_sym].to_s
89
88
  end
90
89
 
91
-
92
90
  Then /^my bibliography should not contain an entry with (?:key|id) "([^"]*)"$/ do |key|
93
91
  assert_nil @bibliography[key.to_sym]
94
92
  end
@@ -97,7 +95,6 @@ Then /^there should be exactly (\d+) match(?:es)?$/ do |matches|
97
95
  assert_equal matches.to_i, @result.length
98
96
  end
99
97
 
100
-
101
98
  Then /^my bibliography should contain (\d+) (\w+)$/ do |count, type|
102
99
  assert_equal count.to_i, @bibliography.q("@#{type.chomp('s')}").length
103
100
  end
@@ -6,11 +6,10 @@ When /^I parse the names "(.*)"$/ do |string|
6
6
  @names = BibTeX::Names.parse(string)
7
7
  end
8
8
 
9
-
10
9
  Then /^the parts should be:$/ do |table|
11
10
  table.hashes.each do |row|
12
11
  assert_equal [row['first'], row['von'], row['last'], row['jr']],
13
- [@name.first, @name.von, @name.last, @name.jr].map(&:to_s)
12
+ [@name.first, @name.von, @name.last, @name.jr].map(&:to_s)
14
13
  # row.each do |k,v|
15
14
  # assert_equal v, @name.send(k).to_s
16
15
  # end
data/lib/bibtex.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # BibTeX-Ruby
3
- # Copyright (C) 2010-2015 Sylvester Keil <sylvester.keil.or.at>
3
+ # Copyright (C) 2010-2015 Sylvester Keil <sylvester.keil.or.at>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -9,11 +9,11 @@
9
9
  #
10
10
  # This program is distributed in the hope that it will be useful,
11
11
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
  # GNU General Public License for more details.
14
14
  #
15
15
  # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
18
18
 
19
19
  require 'digest/md5'
@@ -36,19 +36,17 @@ require 'bibtex/version'
36
36
  # License:: GNU GPL 3.0
37
37
  #
38
38
  module BibTeX
39
-
40
- #
41
- # An instance of the Ruby core class +Logger+.
42
- # Used for logging by BibTeX-Ruby.
43
- #
44
- @log = Logger.new(STDERR)
45
- @log.level = ENV.has_key?('DEBUG') ? Logger::DEBUG : Logger::WARN
46
- @log.datetime_format = '%Y-%m-%d %H:%M:%S'
39
+ #
40
+ # An instance of the Ruby core class +Logger+.
41
+ # Used for logging by BibTeX-Ruby.
42
+ #
43
+ @log = Logger.new(STDERR)
44
+ @log.level = ENV.key?('DEBUG') ? Logger::DEBUG : Logger::WARN
45
+ @log.datetime_format = '%Y-%m-%d %H:%M:%S'
47
46
 
48
47
  class << self
49
48
  attr_accessor :log
50
49
  end
51
-
52
50
  end
53
51
 
54
52
  # Load debugger
@@ -79,5 +77,5 @@ begin
79
77
  require 'bibtex/entry/rdf_converter'
80
78
  require 'bibtex/bibliography/rdf_converter'
81
79
  rescue LoadError
82
- # ignored
80
+ # ignored
83
81
  end
@@ -17,7 +17,6 @@
17
17
  #++
18
18
 
19
19
  module BibTeX
20
-
21
20
  #
22
21
  # The Bibliography class models a BibTeX bibliography;
23
22
  # typically, it corresponds to a `.bib' file.
@@ -28,10 +27,9 @@ module BibTeX
28
27
  include Enumerable
29
28
  include Comparable
30
29
 
31
- @defaults = { :parse_names => true, :parse_months => true }.freeze
30
+ @defaults = { parse_names: true, parse_months: true }.freeze
32
31
 
33
32
  class << self
34
-
35
33
  attr_reader :defaults
36
34
 
37
35
  # Opens and parses the `.bib' file at the given +path+. Returns
@@ -86,7 +84,7 @@ module BibTeX
86
84
  attr_reader :data, :strings, :entries, :errors, :options
87
85
 
88
86
  attr_by_type :article, :book, :journal, :collection, :preamble,
89
- :comment, :meta_content
87
+ :comment, :meta_content
90
88
 
91
89
  def_delegators :@data, :length, :size, :empty?
92
90
  def_delegators :@entries, :key?, :has_key?, :values_at
@@ -96,8 +94,10 @@ module BibTeX
96
94
  # Creates a new bibliography.
97
95
  def initialize(options = {})
98
96
  @options = Bibliography.defaults.merge(options)
99
- @data, @strings, @errors = [], {}, []
100
- @entries = Hash.new { |h,k| h.fetch(k.to_s, nil) }
97
+ @data = []
98
+ @strings = {}
99
+ @errors = []
100
+ @entries = Hash.new { |h, k| h.fetch(k.to_s, nil) }
101
101
 
102
102
  yield self if block_given?
103
103
  end
@@ -105,8 +105,9 @@ module BibTeX
105
105
  def initialize_copy(other)
106
106
  @options = other.options.dup
107
107
  @errors = other.errors.dup
108
- @data, @strings = [], {}
109
- @entries = Hash.new { |h,k| h.fetch(k.to_s, nil) }
108
+ @data = []
109
+ @strings = {}
110
+ @entries = Hash.new { |h, k| h.fetch(k.to_s, nil) }
110
111
 
111
112
  other.each do |element|
112
113
  add element.dup
@@ -127,7 +128,6 @@ module BibTeX
127
128
  alias << add
128
129
  alias push add
129
130
 
130
-
131
131
  # Saves the bibliography to the current path.
132
132
  def save(options = {})
133
133
  save_to(@path, options)
@@ -135,7 +135,7 @@ module BibTeX
135
135
 
136
136
  # Saves the bibliography to a file at the given path. Returns the bibliography.
137
137
  def save_to(path, options = {})
138
- options[:quotes] ||= %w({ })
138
+ options[:quotes] ||= %w[{ }]
139
139
 
140
140
  File.open(path, 'w:UTF-8') do |f|
141
141
  f.write(to_s(options))
@@ -144,7 +144,6 @@ module BibTeX
144
144
  self
145
145
  end
146
146
 
147
-
148
147
  def each
149
148
  if block_given?
150
149
  data.each(&Proc.new)
@@ -154,18 +153,16 @@ module BibTeX
154
153
  end
155
154
  end
156
155
 
157
-
158
156
  def parse_names
159
- entries.each_value { |e| e.parse_names }
157
+ entries.each_value(&:parse_names)
160
158
  self
161
159
  end
162
160
 
163
161
  def parse_months
164
- entries.each_value { |e| e.parse_month }
162
+ entries.each_value(&:parse_month)
165
163
  self
166
164
  end
167
165
 
168
-
169
166
  # Converts all enties using the given filter(s). If an optional block is given
170
167
  # the block is used as a condition (the block will be called with each
171
168
  # entry). @see Entry#convert!
@@ -179,7 +176,6 @@ module BibTeX
179
176
  self
180
177
  end
181
178
 
182
-
183
179
  # Deletes an object, or a list of objects from the bibliography.
184
180
  # If a list of objects is to be deleted, you can either supply the list
185
181
  # of objects or use a query or block to define the list.
@@ -188,14 +184,13 @@ module BibTeX
188
184
  # if the object was not part of the bibliography.
189
185
  def delete(*arguments, &block)
190
186
  objects = q(*arguments, &block).map { |o| o.removed_from_bibliography(self) }
191
- @data = @data - objects
187
+ @data -= objects
192
188
  objects.length == 1 ? objects[0] : objects
193
189
  end
194
190
 
195
191
  alias remove delete
196
192
  alias rm delete
197
193
 
198
-
199
194
  # call-seq:
200
195
  # >> bib[-1]
201
196
  # => Returns the last element of the Bibliography or nil
@@ -221,20 +216,18 @@ module BibTeX
221
216
  # not yield to a block for additional refinement of the query.
222
217
  #
223
218
  def [](*arguments)
224
- raise(ArgumentError, "wrong number of arguments (#{arguments.length} for 1..2)") unless arguments.length.between?(1,2)
219
+ raise(ArgumentError, "wrong number of arguments (#{arguments.length} for 1..2)") unless arguments.length.between?(1, 2)
225
220
 
226
- case
227
- when arguments[0].is_a?(Numeric) || arguments[0].is_a?(Range)
221
+ if arguments[0].is_a?(Numeric) || arguments[0].is_a?(Range)
228
222
  data[*arguments]
229
- when arguments.length == 1
230
- case
231
- when arguments[0].nil?
223
+ elsif arguments.length == 1
224
+ if arguments[0].nil?
232
225
  nil
233
- when arguments[0].respond_to?(:empty?) && arguments[0].empty?
226
+ elsif arguments[0].respond_to?(:empty?) && arguments[0].empty?
234
227
  nil
235
- when arguments[0].is_a?(Symbol)
228
+ elsif arguments[0].is_a?(Symbol)
236
229
  entries[arguments[0]]
237
- when arguments[0].respond_to?(:start_with?) && !arguments[0].start_with?('@', '!@')
230
+ elsif arguments[0].respond_to?(:start_with?) && !arguments[0].start_with?('@', '!@')
238
231
  entries[arguments[0]]
239
232
  else
240
233
  query(*arguments)
@@ -244,7 +237,6 @@ module BibTeX
244
237
  end
245
238
  end
246
239
 
247
-
248
240
  # Returns true if there are object which could not be parsed.
249
241
  def errors?
250
242
  !errors.empty?
@@ -279,7 +271,7 @@ module BibTeX
279
271
  self
280
272
  end
281
273
 
282
- alias :replace_strings :replace
274
+ alias replace_strings replace
283
275
 
284
276
  def join(filter = '')
285
277
  q(filter, &:join)
@@ -318,18 +310,16 @@ module BibTeX
318
310
  # and 'Poe, E. A.' calling this method would convert all three names to
319
311
  # 'Poe, Edgar A.'.
320
312
  def extend_initials!
321
- groups = Hash.new do |h,k|
322
- h[k] = { :prototype => nil, :names => [] }
313
+ groups = Hash.new do |h, k|
314
+ h[k] = { prototype: nil, names: [] }
323
315
  end
324
316
 
325
317
  # group names together
326
318
  names.each do |name|
327
- group = groups[name.sort_order(:initials => true).downcase]
319
+ group = groups[name.sort_order(initials: true).downcase]
328
320
  group[:names] << name
329
321
 
330
- if group[:prototype].nil? || group[:prototype].first.to_s.length < name.first.to_s.length
331
- group[:prototype] = name
332
- end
322
+ group[:prototype] = name if group[:prototype].nil? || group[:prototype].first.to_s.length < name.first.to_s.length
333
323
  end
334
324
 
335
325
  # extend all names in group to prototype
@@ -353,22 +343,20 @@ module BibTeX
353
343
  pattern = Regexp.new(pattern) unless pattern.is_a?(Regexp)
354
344
 
355
345
  block = if block_given?
356
- Proc.new
357
- else
358
- Proc.new { |e| e[field] = value }
359
- end
346
+ Proc.new
347
+ else
348
+ proc { |e| e[field] = value }
349
+ end
360
350
 
361
351
  each_entry do |entry|
362
- if entry.field?(field) && entry[field].to_s =~ pattern
363
- block.call(entry)
364
- end
352
+ block.call(entry) if entry.field?(field) && entry[field].to_s =~ pattern
365
353
  end
366
354
 
367
355
  self
368
356
  end
369
357
 
370
358
  def group_by(*arguments, &block)
371
- groups = Hash.new { |h,k| h[k] = [] }
359
+ groups = Hash.new { |h, k| h[k] = [] }
372
360
 
373
361
  entries.values.each do |e|
374
362
  groups[e.digest(arguments, &block)] << e
@@ -406,7 +394,7 @@ module BibTeX
406
394
 
407
395
  # Returns a Ruby hash representation of the bibliography.
408
396
  def to_hash(options = {})
409
- { :bibliography => map { |o| o.to_hash(options) } }
397
+ { bibliography: map { |o| o.to_hash(options) } }
410
398
  end
411
399
 
412
400
  # Returns a YAML representation of the bibliography.
@@ -430,7 +418,7 @@ module BibTeX
430
418
  require 'rexml/document'
431
419
 
432
420
  xml = REXML::Document.new
433
- xml << REXML::XMLDecl.new('1.0','UTF-8')
421
+ xml << REXML::XMLDecl.new('1.0', 'UTF-8')
434
422
 
435
423
  root = REXML::Element.new('bibtex:file')
436
424
  root.add_namespace('bibtex', 'http://bibtexml.sf.net/')
@@ -443,7 +431,7 @@ module BibTeX
443
431
 
444
432
  # Returns an RDF::Graph representation of the bibliography. The graph
445
433
  # can be serialized using any of the RDF serializer plugins.
446
- def to_rdf(options = {})
434
+ def to_rdf(_options = {})
447
435
  if defined?(::RDF)
448
436
  RDFConverter.convert(self)
449
437
  else
@@ -482,17 +470,19 @@ module BibTeX
482
470
  def query(*arguments, &block)
483
471
  case arguments.length
484
472
  when 0
485
- selector, q = :all, nil
473
+ selector = :all
474
+ q = nil
486
475
  when 1
487
- selector, q = :all, arguments[0]
476
+ selector = :all
477
+ q = arguments[0]
488
478
  when 2
489
479
  selector, q = arguments
490
480
  else
491
481
  raise ArgumentError, "wrong number of arguments (#{arguments.length} for 0..2)"
492
482
  end
493
483
 
494
- filter = block ? Proc.new { |e| e.match?(q) && block.call(e) } :
495
- Proc.new { |e| e.match?(q) }
484
+ filter = block ? proc { |e| e.match?(q) && block.call(e) } :
485
+ proc { |e| e.match?(q) }
496
486
 
497
487
  send(query_handler(selector), &filter)
498
488
  end
@@ -518,19 +508,17 @@ module BibTeX
518
508
  end
519
509
 
520
510
  def select_duplicates_by(*arguments)
521
- arguments = [:year, :title] if arguments.empty?
511
+ arguments = %i[year title] if arguments.empty?
522
512
  block = Proc.new if block_given?
523
513
 
524
- group_by(*arguments) { |digest, entry|
525
-
514
+ group_by(*arguments) do |digest, entry|
526
515
  # 1.8 compatibility
527
516
  # digest = digest[0] if digest.is_a?(Array)
528
517
 
529
518
  digest.gsub(/\s+/, '').downcase
530
519
  digest = block.call(digest, entry) unless block.nil?
531
520
  digest
532
-
533
- }.values.select { |d| d.length > 1 }
521
+ end.values.select { |d| d.length > 1 }
534
522
  end
535
523
 
536
524
  alias duplicates select_duplicates_by
@@ -564,7 +552,7 @@ module BibTeX
564
552
  select_duplicates_by(*arguments, &block).each do |dupes|
565
553
  dupes.shift
566
554
  dupes.each do |dupe|
567
- self.remove dupe
555
+ remove dupe
568
556
  end
569
557
  end
570
558
 
@@ -573,7 +561,7 @@ module BibTeX
573
561
 
574
562
  # Experimental!
575
563
  # Returns a new Bibliography with all duplicates removed.
576
- def uniq(*arguments, &block)
564
+ def uniq(*_arguments)
577
565
  dup.uniq!
578
566
  end
579
567
 
@@ -589,6 +577,5 @@ module BibTeX
589
577
  :select
590
578
  end
591
579
  end
592
-
593
580
  end
594
581
  end