Class: Oddb2xml::SwissmedicDownloader

Inherits:
Downloader
  • Object
show all
Defined in:
lib/oddb2xml/downloader.rb

Instance Attribute Summary

Attributes inherited from Downloader

#agent, #type

Instance Method Summary collapse

Methods inherited from Downloader

#init

Constructor Details

#initialize(type = :orphan, options = {}) ⇒ SwissmedicDownloader

Returns a new instance of SwissmedicDownloader.



274
275
276
277
278
279
280
281
282
283
# File 'lib/oddb2xml/downloader.rb', line 274

def initialize(type=:orphan, options = {})
  @type = type
  @options = options
  case @type
  when :orphan
    @direct_url_link = "https://www.swissmedic.ch/dam/swissmedic/de/dokumente/listen/humanarzneimittel.orphan.xlsx.download.xlsx/humanarzneimittel.xlsx"
  when :package
    @direct_url_link = "https://www.swissmedic.ch/dam/swissmedic/de/dokumente/listen/excel-version_zugelasseneverpackungen.xlsx.download.xlsx/excel-version_zugelasseneverpackungen.xlsx"
  end
end

Instance Method Details

#downloadObject



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/oddb2xml/downloader.rb', line 284

def download
  @type == file = File.join(Oddb2xml::WorkDir, "swissmedic_#{@type}.xlsx")
  if  @options[:calc] and @options[:skip_download] and File.exists?(file) and (Time.now-File.ctime(file)).to_i < 24*60*60
    Oddb2xml.log "SwissmedicDownloader #{__LINE__}: Skip downloading #{file} #{File.size(file)} bytes"
    return File.expand_path(file)
  end
  begin
    FileUtils.rm(File.expand_path(file), :verbose => !defined?(RSpec)) if File.exists?(File.expand_path(file))
    File.open(file, 'w+') do |output|
      output.write open(@direct_url_link).read
    end
    return File.expand_path(file)
  rescue Timeout::Error, Errno::ETIMEDOUT
    retrievable? ? retry : raise
  ensure
    Oddb2xml.download_finished(file, false)
  end
  return File.expand_path(file)
end