bibkeys 0.0.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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+ gem "bundler"
3
+ gem "rake"
4
+ gem "bibtex-ruby", "~> 2.1.2"
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ bibtex-ruby (2.1.2)
5
+ latex-decode (>= 0.0.6)
6
+ multi_json (~> 1.3)
7
+ latex-decode (0.0.12)
8
+ unicode (~> 0.4)
9
+ multi_json (1.3.7)
10
+ rake (0.9.2.2)
11
+ unicode (0.4.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bibtex-ruby (~> 2.1.2)
18
+ bundler
19
+ rake
@@ -0,0 +1,11 @@
1
+ bibkeys.gemspec
2
+ bin
3
+ bin/bibkeys
4
+ Gemfile
5
+ Gemfile.lock
6
+ lib
7
+ lib/bibkeys.rb
8
+ license.txt
9
+ Manifest
10
+ Rakefile
11
+ README.md
@@ -0,0 +1,39 @@
1
+ # Bibkeys
2
+
3
+ A Ruby utility to list all the citation keys in a BibTeX file
4
+
5
+ Lincoln A. Mullen | lincoln@lincolnmullen.com | http://lincolnmullen.com
6
+
7
+ ## Installation
8
+
9
+ You can install bibkeys from [RubyGems](https://rubygems.org/):
10
+
11
+ gem install bibkeys
12
+
13
+ If you don't have it installed already, you'll need to install
14
+ [bibtex-ruby], which does most of the heavy lifting.
15
+
16
+ ## Usage
17
+
18
+ To list all the keys in a BibTeX file:
19
+
20
+ bibkeys bibliography.bib
21
+
22
+ To sort the list of keys:
23
+
24
+ bibkeys -s bibliograph.bib
25
+
26
+ To list all the keys in multiple files:
27
+
28
+ bibkeys bib1.bib bib2.bib etc.bib
29
+
30
+ This program functions as *nix-style utility. Accordingly, it can read
31
+ from stdin:
32
+
33
+ cat bibliography.bib | bibkeys -
34
+
35
+ To save the keys to a file:
36
+
37
+ bibkeys bibliograph.bib > keys.txt
38
+
39
+ [bibtex-ruby]: https://github.com/inukshuk/bibtex-ruby
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rake/clean'
13
+ CLEAN.include('*.gem')
14
+
15
+ desc 'Builds the gem file'
16
+ task :build => ['manifest'] do
17
+ system 'gem build bibkeys.gemspec'
18
+ end
19
+
20
+
21
+ desc 'Updates the Manifest file'
22
+ task :manifest => ['clean'] do
23
+ m = File.open('Manifest', 'w')
24
+ m.print FileList['**/*'].reject{ |f|
25
+ f.start_with?('coverage') || f.end_with?('.bib')
26
+ }.join("\n")
27
+ m.close
28
+ end
29
+
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'bibkeys'
3
+ s.version = '0.0.1'
4
+ s.date = '2012-11-02'
5
+ s.summary = 'List all the keys in BibTeX file'
6
+ s.description = 'A Ruby utility to list all the citation keys in a BibTeX file'
7
+ s.author = 'Lincoln A. Mullen'
8
+ s.email = 'lincoln@lincolnmullen.com'
9
+ s.homepage = 'http://github.com/lmullen/bibkeys'
10
+ s.files = File.open('Manifest').readlines.map(&:chomp)
11
+ s.bindir = 'bin'
12
+ s.executables << 'bibkeys'
13
+ s.license = 'MIT'
14
+ s.add_runtime_dependency('bibtex-ruby', ['~>2.1.2'])
15
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Name:: Bibkeys
4
+ # Author:: Lincoln Mullen | lincoln@lincolnmullen.com
5
+ # Copyright:: Copyright (c) 2012 Lincoln Mullen
6
+ # License:: MIT License | http://lmullen.mit-license.org/
7
+
8
+
9
+ # for use/testing when no gem is installed
10
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
11
+
12
+ require 'optparse'
13
+ require 'bibkeys'
14
+
15
+ # set default options
16
+ options = {}
17
+ options[:sort] = false
18
+
19
+ opts = OptionParser.new do|opts|
20
+
21
+ # help options
22
+ opts.banner = "Usage: bibkeys [-s] bibliography.bib [bibliography2.bib]\n bibkeys [-s] -\nOptions:"
23
+ opts.on( '-h', '--help', 'Display help screen' ) do
24
+ puts opts
25
+ exit
26
+ end
27
+
28
+ # should we sort?
29
+ opts.on('-s', '--sort', 'Sort the list of keys' ) do
30
+ options[:sort] = true
31
+ end
32
+
33
+ end
34
+ opts.parse! # strips all non-filename arguments from ARGV
35
+
36
+ # If values have been passed as filenames or stdin, then pass those
37
+ # values as an input stream to a Bibkeys class to be parsed.
38
+ if ARGV.any?
39
+ Bibkeys.new( ARGF.read , options[:sort] ).list
40
+ else
41
+ puts "Please pass a BibTeX filename or BibTeX input to stdin."
42
+ end
@@ -0,0 +1,36 @@
1
+ # Name:: Bibkeys
2
+ # Author:: Lincoln Mullen | lincoln@lincolnmullen.com
3
+ # Copyright:: Copyright (c) 2012 Lincoln Mullen
4
+ # License:: MIT License | http://lmullen.mit-license.org/
5
+
6
+ require 'bibtex'
7
+
8
+ # This class parses a stream of BibTeX input passed to it and provides a
9
+ # method to list its keys, sorted or unsorted.
10
+ class Bibkeys
11
+
12
+ # Parses an input stream as if it were a BibTeX file
13
+ def initialize ( stream , sort=false )
14
+ @bib = BibTeX.parse( stream )
15
+ @sort = sort
16
+ end
17
+
18
+
19
+ # List all the keys in the BibTeX file
20
+ def list
21
+
22
+ keys = Array.new
23
+
24
+ @bib.each do |entry|
25
+ keys.push entry.key
26
+ end
27
+
28
+ if @sort
29
+ puts keys.sort
30
+ else
31
+ puts keys
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2012 Lincoln A. Mullen <lincoln@lincolnmullen.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the “Software”), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bibkeys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lincoln A. Mullen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bibtex-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.2
30
+ description: A Ruby utility to list all the citation keys in a BibTeX file
31
+ email: lincoln@lincolnmullen.com
32
+ executables:
33
+ - bibkeys
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - bibkeys.gemspec
38
+ - bin/bibkeys
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - lib/bibkeys.rb
42
+ - license.txt
43
+ - Manifest
44
+ - Rakefile
45
+ - README.md
46
+ homepage: http://github.com/lmullen/bibkeys
47
+ licenses:
48
+ - MIT
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ segments:
60
+ - 0
61
+ hash: -4548692308244964840
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.24
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: List all the keys in BibTeX file
74
+ test_files: []