Class: BibSync::JabRefFormatter

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/bibsync/jabref_formatter.rb

Constant Summary

Constants included from Log

Log::Blue, Log::Level, Log::Red, Log::Reset, Log::Yellow

Instance Method Summary collapse

Methods included from Log

#log

Instance Method Details

#call(file) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bibsync/jabref_formatter.rb', line 5

def call(file)
  if File.read(file, 80) !~ /JabRef/
    notice 'Transforming file with JabRef'
    tmp_file = "#{file}.formatted.bib"
    begin
      `jabref --primp #{Shellwords.escape File.join(File.dirname(__FILE__), 'jabref.xml')} --nogui --import #{Shellwords.escape file} --output #{Shellwords.escape tmp_file} 2>&1 >/dev/null`
      File.rename(tmp_file, file) if File.exists?(tmp_file)
    ensure
      File.unlink(tmp_file) rescue nil
    end
  end
end