Class: Arxiv::Downloader::HTMLArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/arxiv/downloader/html_archive.rb

Constant Summary collapse

ASSET_SELECTORS =
{
  'img[src]'               => 'src',
  'script[src]'            => 'src',
  'link[rel="stylesheet"]' => 'href'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(identifier, client:, assets_cache:) ⇒ HTMLArchive

Returns a new instance of HTMLArchive.



14
15
16
17
18
# File 'lib/arxiv/downloader/html_archive.rb', line 14

def initialize identifier, client:, assets_cache:
  @identifier   = identifier
  @client       = client
  @assets_cache = assets_cache
end

Instance Method Details

#download(to:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/arxiv/downloader/html_archive.rb', line 20

def download to:
  FileUtils.mkdir_p to

  document = Nokogiri::HTML @client.get(html_url).to_s
  ASSET_SELECTORS.each do |selector, attribute|
    document.css(selector).each { |node| process node, attribute, to }
  end

  File.write File.join(to, "#{@identifier.id}.html"), document.to_html
end