Class: Oddb2xml::SwissmedicDownloader
- Inherits:
-
Downloader
- Object
- Downloader
- Oddb2xml::SwissmedicDownloader
- Defined in:
- lib/oddb2xml/downloader.rb
Instance Attribute Summary
Attributes inherited from Downloader
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(type = :orphan) ⇒ SwissmedicDownloader
constructor
A new instance of SwissmedicDownloader.
Methods inherited from Downloader
Constructor Details
#initialize(type = :orphan) ⇒ SwissmedicDownloader
Returns a new instance of SwissmedicDownloader.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/oddb2xml/downloader.rb', line 229 def initialize(type=:orphan) @type = type case @type when :orphan action = "arzneimittel/00156/00221/00222/00223/00224/00227/00228/index.html?lang=de" @xpath = "//div[@id='sprungmarke10_3']//a[@title='Humanarzneimittel']" when :fridge action = "arzneimittel/00156/00221/00222/00235/index.html?lang=de" @xpath = "//div[@id='sprungmarke10_2']//a[@title='Excel-Version']" when :package action = "arzneimittel/00156/00221/00222/00230/index.html?lang=de" @xpath = "//div[@id='sprungmarke10_7']//a[@title='Excel-Version Zugelassene Verpackungen*']" end url = "http://www.swissmedic.ch/#{action}" super({}, url) end |
Instance Method Details
#download ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/oddb2xml/downloader.rb', line 245 def download @type == :orphan ? file = "swissmedic_#{@type}.xls" : file = "swissmedic_#{@type}.xlsx" begin page = @agent.get(@url) if link_node = page.search(@xpath).first link = Mechanize::Page::Link.new(link_node, @agent, page) unless Oddb2xml.skip_download(file) response = link.click response.save_as(file) response = nil # win end end return File.(file) rescue Timeout::Error, Errno::ETIMEDOUT retrievable? ? retry : raise ensure Oddb2xml.download_finished(file, false) end end |