Class: BibSync::Actions::CheckArXivVersions

Inherits:
Object
  • Object
show all
Includes:
Log, Utils
Defined in:
lib/bibsync/actions/check_arxiv_versions.rb

Constant Summary collapse

SliceSize =
20

Constants included from Log

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

Instance Method Summary collapse

Methods included from Utils

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

Methods included from Log

#log

Constructor Details

#initialize(options) ⇒ CheckArXivVersions

Returns a new instance of CheckArXivVersions.



9
10
11
12
13
# File 'lib/bibsync/actions/check_arxiv_versions.rb', line 9

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

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bibsync/actions/check_arxiv_versions.rb', line 15

def run
  notice 'Check for newer version on arXiv'
  @bib.select {|e| e[:arxiv] }.each_slice(SliceSize) do |entry|
    begin
      xml = fetch_xml('http://export.arxiv.org/api/query', id_list: entry.map{|e| arxiv_id(e, version: false, prefix: true) }.join(','), max_results: SliceSize)
      xml.get_elements('//entry').each_with_index do |e, i|
        id = e.elements['id'].text.gsub('http://arxiv.org/abs/', '')
        if id != entry[i][:arxiv]
          info("#{entry[i][:arxiv]} replaced by http://arxiv.org/pdf/#{id}", key: entry[i])
          arxiv_download(@dir, id) if @update
        end
      end
    rescue => ex
      error('arXiv query failed', ex: ex)
    end
  end

end