Class: BibSync::Actions::SynchronizeFiles
- Inherits:
-
Object
- Object
- BibSync::Actions::SynchronizeFiles
- Defined in:
- lib/bibsync/actions/synchronize_files.rb
Constant Summary collapse
- FileTypes =
%w(djvu pdf ps)
Constants included from Log
Log::Blue, Log::Level, Log::Red, Log::Reset, Log::Yellow
Instance Method Summary collapse
-
#initialize(options) ⇒ SynchronizeFiles
constructor
A new instance of SynchronizeFiles.
- #run ⇒ Object
Methods included from Log
Methods included from Utils
#arxiv_download, #arxiv_id, #fetch, #fetch_xml, #name_without_ext
Constructor Details
#initialize(options) ⇒ SynchronizeFiles
Returns a new instance of SynchronizeFiles.
9 10 11 12 13 |
# File 'lib/bibsync/actions/synchronize_files.rb', line 9 def initialize() raise 'Option --bib is required' unless @bib = [:bib] raise 'Option --dir is required' unless @dir = [:dir] @dir = File.join(@dir, '**') unless [:non_recursive] end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bibsync/actions/synchronize_files.rb', line 15 def run notice 'Synchronize with files' files = {} Dir[File.join(@dir, "*.{#{FileTypes.join(',')}}")].sort.each do |file| name = File.basename(file) if name =~ /\A[\w\.\-]+\Z/ key = name_without_ext(name) raise "Duplicate file #{name}" if files[key] files[key] = file else warning('File with invalid name', key: name) end end files.each do |key, file| unless entry = @bib[key] info('New file', key: key) entry = Entry.new(key: key) @bib << entry end entry.type ||= :ARTICLE entry.file = file end end |