Class: BibSync::Actions::JabRefFormat

Inherits:
Object
  • Object
show all
Includes:
Log, Utils
Defined in:
lib/bibsync/actions/jabref_format.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

Methods included from Utils

#arxiv_download, #arxiv_id, #fetch, #fetch_html, #fetch_xml, #name_without_ext

Constructor Details

#initialize(options) ⇒ JabRefFormat

Returns a new instance of JabRefFormat.



7
8
9
# File 'lib/bibsync/actions/jabref_format.rb', line 7

def initialize(options)
  raise 'Option --bib is required' unless @bib = options[:bib]
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
# File 'lib/bibsync/actions/jabref_format.rb', line 11

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