Class: BibSync::Actions::SynchronizeMetadata

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

Constructor Details

#initialize(options) ⇒ SynchronizeMetadata

Returns a new instance of SynchronizeMetadata.



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

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

Instance Method Details

#runObject



12
13
14
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
# File 'lib/bibsync/actions/synchronize_metadata.rb', line 12

def run
  notice 'Synchronize with arXiv and DOI'

  @bib.to_a.each do |entry|
    next if entry.comment?

    entry.delete(:abstract) if @force

    if @force || !(entry[:title] && entry[:author] && entry[:year])
      if entry[:arxiv]
        if entry.key == arxiv_id(entry, prefix: false, version: true)
          entry = rename_arxiv_file(entry)
          next unless entry
        end
        update_arxiv(entry)
      end

      update_doi(entry) if entry[:doi]
    end

    if entry[:doi] =~ /\A10\.1103\// && !entry[:abstract]
      update_aps_abstract(entry)
    end

    # Add timestamp when this entry was added
    entry[:added] ||= Date.today.to_s
  end
end