Class: BibSync::Actions::CheckArXivVersions
- Inherits:
-
Object
- Object
- BibSync::Actions::CheckArXivVersions
- 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
-
#initialize(options) ⇒ CheckArXivVersions
constructor
A new instance of CheckArXivVersions.
- #run ⇒ Object
Methods included from Utils
#arxiv_download, #arxiv_id, #fetch, #fetch_html, #fetch_xml, #name_without_ext
Methods included from 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() raise 'Option --bib is required' unless @bib = [:bib] raise 'Option --dir is required' unless @dir = [:dir] @update = [:update] end |
Instance Method Details
#run ⇒ Object
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.xpath('//entry/id').map(&:content).each_with_index do |id, i| id.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 |