Class: BibSync::Actions::FetchFromArXiv
- Inherits:
-
Object
- Object
- BibSync::Actions::FetchFromArXiv
- Defined in:
- lib/bibsync/actions/fetch_from_arxiv.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) ⇒ FetchFromArXiv
constructor
A new instance of FetchFromArXiv.
- #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) ⇒ FetchFromArXiv
Returns a new instance of FetchFromArXiv.
9 10 11 12 |
# File 'lib/bibsync/actions/fetch_from_arxiv.rb', line 9 def initialize() raise 'Option --fetch is required' unless @fetch = [:fetch] raise 'Option --dir is required' unless @dir = [:dir] end |
Instance Method Details
#run ⇒ Object
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 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bibsync/actions/fetch_from_arxiv.rb', line 14 def run arxivs = [] urls = [] @fetch.each do |url| if url =~ /\A(\d+\.\d+)(v\d+)?\Z/ arxivs << $1 elsif url =~ %r{\Ahttp://arxiv.org/abs/(\d+\.\d+)\Z} arxivs << $1 else urls << url end end unless urls.empty? notice 'Starting browser for non-arXiv urls' urls.each do |url| info "Opening #{url}" `xdg-open #{Shellwords.escape url}` end end unless arxivs.empty? notice 'Downloading from arXiv' arxivs.each_slice(SliceSize) do |ids| begin xml = fetch_xml('http://export.arxiv.org/api/query', id_list: ids.join(','), max_results: SliceSize) xml.xpath('//entry/id').map(&:content).each_with_index do |id, i| id.gsub!('http://arxiv.org/abs/', '') info 'arXiv download', key: id arxiv_download(@dir, id) end rescue => ex error('arXiv query failed', ex: ex) end end end end |