Class: Oddb2xml::Cli

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

Constant Summary collapse

SUBJECTS =
%w[product article]
ADDITIONS =
%w[substance limitation interaction code]
OPTIONALS =
%w[fi fi_product]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cli

Returns a new instance of Cli.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oddb2xml/cli.rb', line 20

def initialize(args)
  @options = args
  Oddb2xml.save_options(@options)
  @mutex = Mutex.new
  # product
  @items = {} # Items from Preparations.xml in BAG, using GTINs as key
  @refdata_types = {} # Base index from refdata
  @lppvs = {} # lppv.txt from files repo
  @infos = {} # [option] FI from SwissmedicInfo
  @packs = {} # [option] Packungen from Swissmedic for dat
  @infos_zur_rose  = {} # [addition] infos_zur_rose and other infos from zurrose transfer.txt
  @migel   = {} # [addition] additional Non Pharma products from files repo
  @actions = [] # [addition] interactions from epha
  @orphan = [] # [addition] Orphaned drugs from Swissmedic xls
  # addresses
  @companies = [] # betrieb
  @people    = [] # medizinalperson
  @_message = false
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/oddb2xml/cli.rb', line 16

def options
  @options
end

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/oddb2xml/cli.rb', line 39

def run
  threads = []
  files2rm = Dir.glob(File.join(Downloads, '*'))
  FileUtils.rm_f(files2rm, :verbose => @options[:log]) if files2rm.size > 0 and not Oddb2xml.skip_download?
  if @options[:calc] and not @options[:extended]
    threads << download(:package) # swissmedic
  elsif @options[:address]
    [:company, :person].each do |type|
      threads << download(type) # medregbm.admin
    end
  else
    if @options[:format] != :dat
      if @options[:fi]
        threads << download(:fachinfo) # swissmedic-info
      end
      threads << download(:orphan) # swissmedic
      threads << download(:interaction) # epha
    end
    if @options[:nonpharma]
      threads << download(:migel) # oddb2xml_files
    end
    threads << download(:zurrose)
    threads << download(:package) # swissmedic
    threads << download(:lppv) # oddb2xml_files
    threads << download(:bag) # bag.e-mediat
    types.each do |type|
      threads << download(:refdata, type) # refdata
    end
  end
  begin
    # threads.map(&:join) # TODO
  rescue SystemExit
    @mutex.synchronize do
      if @_message
        puts "(Aborted)"
        puts "Please install SSLv3 CA certificates on your machine."
        puts "You can check with `ruby -ropenssl -e 'p OpenSSL::X509::DEFAULT_CERT_FILE'`."
        puts "See README."
      end
    end
    exit
  end
  build
  compress if @options[:compress_ext]
  report
end