Class: ODDB::SwissmedicJournalPlugin

Inherits:
Plugin show all
Defined in:
src/plugin/swissmedicjournal.rb

Constant Summary

RECIPIENTS =
[
  'matthijs.ouwerkerk@just-medical.com',
]

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

Instance Method Summary (collapse)

Methods inherited from Plugin

#initialize, #l10n_sessions, #log_info, #recipients, #resolve_link, #update_rss_feeds

Methods included from HttpFile

#http_body, #http_file

Constructor Details

This class inherits a constructor from ODDB::Plugin

Instance Method Details

- (Object) report



13
14
15
16
17
18
19
20
21
22
23
# File 'src/plugin/swissmedicjournal.rb', line 13

def report
  atcless = @app.atcless_sequences.collect { |sequence|
    resolve_link(sequence.pointer)  
  }.sort
  lines = [
    "ODDB::SwissmedicJournalPlugin - Report #{@month}",
    "Total Sequences without ATC-Class: #{atcless.size}",
    atcless,
  ]
  lines.flatten.join("\n")
end

- (Object) update(month)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'src/plugin/swissmedicjournal.rb', line 24

def update(month)
  agent = Mechanize.new
  main = agent.get 'http://www.swissmedic.ch/org/00064/00065/index.html'
  link = main.links.find do |node|
    /Swissmedic\s*Journal/iu.match node.attributes['title']
  end or raise 'unable to identify url for Swissmedic-Journal'
  smj = link.click

  latest = File.join(ARCHIVE_PATH, 'pdf', 'Swissmedic-Journal-latest.pdf')
  unless File.exist?(latest) && File.read(latest) == smj.body
    filename = month.strftime('%m_%Y.pdf')
    target = File.join(ARCHIVE_PATH, 'pdf', filename)
    if File.exist?(target) && File.read(target) != smj.body
      raise "Safety-catch: cannot overwrite #{target} with data from #{link.attributes['href']}"
    end
    smj.save latest
    smj.save target
  end
rescue Mechanize::ResponseCodeError
end