bibsync 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bibsync.rb +1 -0
- data/lib/bibsync/actions/check_arxiv_versions.rb +2 -2
- data/lib/bibsync/actions/determine_arxiv_doi.rb +2 -2
- data/lib/bibsync/actions/fetch_from_arxiv.rb +2 -2
- data/lib/bibsync/actions/find_my_citations.rb +2 -2
- data/lib/bibsync/actions/jabref_format.rb +1 -1
- data/lib/bibsync/actions/synchronize_files.rb +2 -2
- data/lib/bibsync/actions/synchronize_metadata.rb +1 -1
- data/lib/bibsync/actions/validate.rb +1 -1
- data/lib/bibsync/bibliography.rb +5 -21
- data/lib/bibsync/command.rb +1 -1
- data/lib/bibsync/entry.rb +6 -7
- data/lib/bibsync/log.rb +6 -24
- data/lib/bibsync/version.rb +1 -1
- data/test/test_bibliography.rb +0 -3
- data/test/test_entry.rb +6 -0
- metadata +1 -1
data/lib/bibsync.rb
CHANGED
@@ -7,8 +7,8 @@ module BibSync
|
|
7
7
|
SliceSize = 20
|
8
8
|
|
9
9
|
def initialize(options)
|
10
|
-
raise 'Option
|
11
|
-
raise 'Option
|
10
|
+
raise 'Option --bib is required' unless @bib = options[:bib]
|
11
|
+
raise 'Option --dir is required' unless @dir = options[:dir]
|
12
12
|
@update = options[:update]
|
13
13
|
end
|
14
14
|
|
@@ -5,7 +5,7 @@ module BibSync
|
|
5
5
|
include Log
|
6
6
|
|
7
7
|
def initialize(options)
|
8
|
-
raise 'Option
|
8
|
+
raise 'Option --bib is required' unless @bib = options[:bib]
|
9
9
|
@force = options[:resync]
|
10
10
|
end
|
11
11
|
|
@@ -27,7 +27,7 @@ module BibSync
|
|
27
27
|
|
28
28
|
def determine_arxiv_and_doi(entry)
|
29
29
|
if file = entry.file
|
30
|
-
if file[:type] ==
|
30
|
+
if file[:type] == 'PDF' && !entry[:arxiv] && !entry[:doi]
|
31
31
|
debug('Searching for arXiv or doi identifier in pdf file', key: entry)
|
32
32
|
text = `pdftotext -f 1 -l 2 #{Shellwords.escape file[:path]} - 2>/dev/null`
|
33
33
|
entry[:arxiv] = $1 if text =~ /arXiv:\s*([\w\.\/\-]+)/
|
@@ -7,8 +7,8 @@ module BibSync
|
|
7
7
|
include Utils
|
8
8
|
|
9
9
|
def initialize(options)
|
10
|
-
raise 'Option
|
11
|
-
raise 'Option
|
10
|
+
raise 'Option --fetch is required' unless @fetch = options[:fetch]
|
11
|
+
raise 'Option --dir is required' unless @dir = options[:dir]
|
12
12
|
end
|
13
13
|
|
14
14
|
def run
|
@@ -5,8 +5,8 @@ module BibSync
|
|
5
5
|
include Utils
|
6
6
|
|
7
7
|
def initialize(options)
|
8
|
-
raise 'Option
|
9
|
-
raise 'Option
|
8
|
+
raise 'Option --bib is required' unless @bib = options[:bib]
|
9
|
+
raise 'Option --citedbyme is required' unless @dir = options[:citedbyme]
|
10
10
|
raise "#{@dir} is not a directory" unless File.directory?(@dir)
|
11
11
|
end
|
12
12
|
|
@@ -7,8 +7,8 @@ module BibSync
|
|
7
7
|
FileTypes = %w(djvu pdf ps)
|
8
8
|
|
9
9
|
def initialize(options)
|
10
|
-
raise 'Option
|
11
|
-
raise 'Option
|
10
|
+
raise 'Option --bib is required' unless @bib = options[:bib]
|
11
|
+
raise 'Option --dir is required' unless @dir = options[:dir]
|
12
12
|
end
|
13
13
|
|
14
14
|
def run
|
data/lib/bibsync/bibliography.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
module BibSync
|
2
2
|
class Bibliography
|
3
3
|
include Enumerable
|
4
|
+
extend Forwardable
|
4
5
|
|
5
6
|
attr_reader :file
|
6
7
|
attr_accessor :save_hook
|
8
|
+
def_delegators :@entries, :empty?, :size
|
9
|
+
def_delegator :@entries, :each_value, :each
|
7
10
|
|
8
11
|
def initialize(file = nil)
|
9
12
|
@entries, @save_hook = {}, nil
|
@@ -18,14 +21,6 @@ module BibSync
|
|
18
21
|
@dirty = true
|
19
22
|
end
|
20
23
|
|
21
|
-
def empty?
|
22
|
-
@entries.empty?
|
23
|
-
end
|
24
|
-
|
25
|
-
def size
|
26
|
-
@entries.size
|
27
|
-
end
|
28
|
-
|
29
24
|
def [](key)
|
30
25
|
@entries[key.to_s]
|
31
26
|
end
|
@@ -51,14 +46,9 @@ module BibSync
|
|
51
46
|
Pathname.new(file).realpath.relative_path_from(Pathname.new(bibpath)).to_s
|
52
47
|
end
|
53
48
|
|
54
|
-
def each(&block)
|
55
|
-
@entries.each_value(&block)
|
56
|
-
end
|
57
|
-
|
58
49
|
def save(file = nil)
|
59
50
|
if file
|
60
51
|
@file = file
|
61
|
-
@parent_path = nil
|
62
52
|
dirty!
|
63
53
|
end
|
64
54
|
|
@@ -82,14 +72,8 @@ module BibSync
|
|
82
72
|
dirty!
|
83
73
|
end
|
84
74
|
|
85
|
-
def load(file)
|
86
|
-
parse(File.read(file)) if file && File.exists?(file)
|
87
|
-
@file = file
|
88
|
-
@dirty = false
|
89
|
-
end
|
90
|
-
|
91
|
-
def load!(file)
|
92
|
-
parse(File.read(file))
|
75
|
+
def load(file, check = true)
|
76
|
+
parse(File.read(file)) if !check || (file && File.exists?(file))
|
93
77
|
@file = file
|
94
78
|
@dirty = false
|
95
79
|
end
|
data/lib/bibsync/command.rb
CHANGED
data/lib/bibsync/entry.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
module BibSync
|
2
2
|
class Entry
|
3
3
|
include Enumerable
|
4
|
+
extend Forwardable
|
4
5
|
|
5
6
|
attr_accessor :bibliography, :type
|
6
7
|
attr_reader :key
|
8
|
+
def_delegators :@fields, :empty?, :size, :each
|
7
9
|
|
8
10
|
def self.parse(text)
|
9
11
|
Entry.new.tap {|e| e.parse(text) }
|
10
12
|
end
|
11
13
|
|
12
14
|
def initialize(fields = {})
|
15
|
+
@fields = {}
|
13
16
|
self.key = fields.delete(:key) if fields.include?(:key)
|
14
17
|
self.type = fields.delete(:type) if fields.include?(:type)
|
15
|
-
|
18
|
+
fields.each {|k,v| self[k] = v }
|
16
19
|
end
|
17
20
|
|
18
21
|
def key=(key)
|
@@ -39,7 +42,7 @@ module BibSync
|
|
39
42
|
raise 'No bibliography set' unless bibliography
|
40
43
|
_, file, type = self[:file].split(':', 3)
|
41
44
|
path = File.join(File.absolute_path(File.dirname(bibliography.file)), file)
|
42
|
-
{ name: File.basename(path), type: type.upcase
|
45
|
+
{ name: File.basename(path), type: type.upcase, path: path }
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
@@ -68,10 +71,6 @@ module BibSync
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
def each(&block)
|
72
|
-
@fields.each(&block)
|
73
|
-
end
|
74
|
-
|
75
74
|
def comment?
|
76
75
|
type.to_s.downcase == 'comment'
|
77
76
|
end
|
@@ -158,7 +157,7 @@ module BibSync
|
|
158
157
|
end
|
159
158
|
|
160
159
|
def convert_key(key)
|
161
|
-
key.to_s.downcase
|
160
|
+
key.to_s.downcase
|
162
161
|
end
|
163
162
|
end
|
164
163
|
end
|
data/lib/bibsync/log.rb
CHANGED
@@ -20,34 +20,16 @@ module BibSync
|
|
20
20
|
self.trace = false
|
21
21
|
self.level = :info
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def info(message, opts = {})
|
28
|
-
log(:info, message, opts)
|
29
|
-
end
|
30
|
-
|
31
|
-
def notice(message, opts = {})
|
32
|
-
log(:notice, message, opts)
|
33
|
-
end
|
34
|
-
|
35
|
-
def warning(message, opts = {})
|
36
|
-
log(:warning, message, opts)
|
37
|
-
end
|
38
|
-
|
39
|
-
def error(message, opts = {})
|
40
|
-
log(:error, message, opts)
|
23
|
+
[:debug, :info, :notice, :warning, :error].each do |level|
|
24
|
+
define_method level do |message, opts = {}|
|
25
|
+
log(level, message, opts)
|
26
|
+
end
|
41
27
|
end
|
42
28
|
|
43
29
|
def log(level, message, opts = {})
|
44
30
|
return if Level.keys.index(level) < Level.keys.index(Log.level)
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
if color = Level[level]
|
49
|
-
message = "#{color}#{message}#{Reset}"
|
50
|
-
end
|
31
|
+
message = "#{message} - #{opts[:ex].message}" if opts[:ex]
|
32
|
+
message = "#{Level[level]}#{message}#{Reset}" if Level[level]
|
51
33
|
if key = opts[:key]
|
52
34
|
key = key.key if key.respond_to? :key
|
53
35
|
message = "#{key} : #{message}"
|
data/lib/bibsync/version.rb
CHANGED
data/test/test_bibliography.rb
CHANGED
data/test/test_entry.rb
CHANGED
@@ -49,6 +49,12 @@ describe BibSync::Entry do
|
|
49
49
|
describe '#each' do
|
50
50
|
end
|
51
51
|
|
52
|
+
describe '#size' do
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#empty?' do
|
56
|
+
end
|
57
|
+
|
52
58
|
describe '#comment?' do
|
53
59
|
it 'should return true for a comment entry' do
|
54
60
|
BibSync::Entry.new(type: 'coMMent').comment?.must_equal true
|