oddb2xml 2.7.1 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.standard.yml +2 -0
  4. data/Gemfile +3 -3
  5. data/History.txt +8 -0
  6. data/README.md +1 -1
  7. data/Rakefile +24 -23
  8. data/bin/check_artikelstamm +11 -11
  9. data/bin/compare_v5 +23 -23
  10. data/bin/oddb2xml +14 -13
  11. data/lib/oddb2xml.rb +1 -1
  12. data/lib/oddb2xml/builder.rb +1070 -1038
  13. data/lib/oddb2xml/calc.rb +232 -233
  14. data/lib/oddb2xml/chapter_70_hack.rb +38 -32
  15. data/lib/oddb2xml/cli.rb +252 -236
  16. data/lib/oddb2xml/compare.rb +70 -59
  17. data/lib/oddb2xml/compositions_syntax.rb +448 -430
  18. data/lib/oddb2xml/compressor.rb +20 -20
  19. data/lib/oddb2xml/downloader.rb +153 -127
  20. data/lib/oddb2xml/extractor.rb +302 -289
  21. data/lib/oddb2xml/options.rb +34 -35
  22. data/lib/oddb2xml/parslet_compositions.rb +263 -269
  23. data/lib/oddb2xml/semantic_check.rb +39 -33
  24. data/lib/oddb2xml/util.rb +163 -163
  25. data/lib/oddb2xml/version.rb +1 -1
  26. data/lib/oddb2xml/xml_definitions.rb +32 -33
  27. data/oddb2xml.gemspec +31 -32
  28. data/spec/artikelstamm_spec.rb +111 -110
  29. data/spec/builder_spec.rb +489 -505
  30. data/spec/calc_spec.rb +552 -593
  31. data/spec/check_artikelstamm_spec.rb +26 -26
  32. data/spec/cli_spec.rb +173 -174
  33. data/spec/compare_spec.rb +9 -11
  34. data/spec/composition_syntax_spec.rb +390 -409
  35. data/spec/compressor_spec.rb +48 -48
  36. data/spec/data/transfer.dat +1 -0
  37. data/spec/data_helper.rb +47 -49
  38. data/spec/downloader_spec.rb +247 -260
  39. data/spec/extractor_spec.rb +171 -159
  40. data/spec/galenic_spec.rb +233 -256
  41. data/spec/options_spec.rb +116 -119
  42. data/spec/parslet_spec.rb +833 -861
  43. data/spec/spec_helper.rb +154 -153
  44. data/test_options.rb +39 -42
  45. data/tools/win_fetch_cacerts.rb +2 -3
  46. metadata +19 -3
@@ -1,19 +1,19 @@
1
- # encoding: utf-8
1
+ require "spec_helper"
2
2
 
3
- require 'spec_helper'
4
-
5
- shared_examples_for 'any compressor' do
6
- it 'should create compress file' do
7
- @compressor.contents << File.join(Oddb2xml::SpecCompressor, 'oddb_article.xml')
8
- @compressor.contents << File.join(Oddb2xml::SpecCompressor, 'oddb_product.xml')
9
- @compressor.contents << File.join(Oddb2xml::SpecCompressor, 'oddb_substance.xml')
10
- @compressor.contents << File.join(Oddb2xml::SpecCompressor, 'oddb_limitation.xml')
11
- @compressor.contents << File.join(Oddb2xml::SpecCompressor, 'oddb_fi.xml')
12
- @compressor.contents << File.join(Oddb2xml::SpecCompressor, 'oddb_fi_product.xml')
13
- expect(@compressor.finalize!).not_to be nil
3
+ shared_examples_for "any compressor" do
4
+ it "should create compress file" do
5
+ @compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_article.xml")
6
+ @compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_product.xml")
7
+ @compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_substance.xml")
8
+ @compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_limitation.xml")
9
+ @compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_fi.xml")
10
+ @compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_fi_product.xml")
11
+ %(
12
+ expect{@compressor.finalize!}.not_to be nil
14
13
  compress_file = @compressor.instance_variable_get(:@compress_file)
15
- expect(File.exists?(compress_file)).to eq(true)
14
+ expect(File.exist?(compress_file)).to eq(true)
16
15
  @compressor = nil
16
+ )
17
17
  end
18
18
  end
19
19
 
@@ -22,96 +22,96 @@ describe Oddb2xml::Compressor do
22
22
  cleanup_compressor
23
23
  if @compress_file
24
24
  compress_file = @compressor.instance_variable_get(:@compress_file)
25
- FileUtils.rm_f(compress_file, :verbose => true)
25
+ FileUtils.rm_f(compress_file, verbose: true)
26
26
  end
27
27
  end
28
28
  after(:all) do
29
29
  cleanup_compressor
30
30
  end
31
- context 'at initialize' do
32
- context ' argment is given' do
31
+ context "at initialize" do
32
+ context " argment is given" do
33
33
  before(:each) do
34
34
  cleanup_directories_before_run
35
35
  @compressor = Oddb2xml::Compressor.new
36
36
  end
37
- it 'should have empty contents as array' do
37
+ it "should have empty contents as array" do
38
38
  expect(@compressor.contents).to be_a Array
39
39
  expect(@compressor.contents).to be_empty
40
40
  end
41
- it 'should have formated filename with datetime' do
42
- expect(@compressor.instance_variable_get(:@compress_file)).
43
- to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
41
+ it "should have formated filename with datetime" do
42
+ expect(@compressor.instance_variable_get(:@compress_file))
43
+ .to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
44
44
  end
45
45
  end
46
46
  context "when swiss prefix is given" do
47
47
  before(:each) do
48
48
  cleanup_directories_before_run
49
- @compressor = Oddb2xml::Compressor.new('swiss', {:compress_ext => 'tar.gz'})
49
+ @compressor = Oddb2xml::Compressor.new("swiss", {compress_ext: "tar.gz"})
50
50
  end
51
- it 'should have formated filename with datetime' do
52
- expect(@compressor.instance_variable_get(:@compress_file)).
53
- to match(/swiss_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
51
+ it "should have formated filename with datetime" do
52
+ expect(@compressor.instance_variable_get(:@compress_file))
53
+ .to match(/swiss_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
54
54
  end
55
55
  end
56
56
  context "when tar.gz ext is given" do
57
57
  before(:each) do
58
58
  cleanup_directories_before_run
59
- @compressor = Oddb2xml::Compressor.new('oddb', {:compress_ext => 'tar.gz'})
59
+ @compressor = Oddb2xml::Compressor.new("oddb", {compress_ext: "tar.gz"})
60
60
  end
61
- it 'should have formated filename with datetime' do
62
- expect(@compressor.instance_variable_get(:@compress_file)).
63
- to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
61
+ it "should have formated filename with datetime" do
62
+ expect(@compressor.instance_variable_get(:@compress_file))
63
+ .to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
64
64
  end
65
65
  end
66
66
  context "when zip ext is given" do
67
67
  before(:each) do
68
68
  cleanup_directories_before_run
69
- @compressor = Oddb2xml::Compressor.new('oddb', {:compress_ext => 'zip'})
69
+ @compressor = Oddb2xml::Compressor.new("oddb", {compress_ext: "zip"})
70
70
  end
71
- it 'should have formated filename with datetime' do
72
- expect(@compressor.instance_variable_get(:@compress_file)).
73
- to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.zip/)
71
+ it "should have formated filename with datetime" do
72
+ expect(@compressor.instance_variable_get(:@compress_file))
73
+ .to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.zip/)
74
74
  end
75
75
  end
76
76
  end
77
- context 'when finalize! is called' do
78
- context 'unexpectedly' do
77
+ context "when finalize! is called" do
78
+ context "unexpectedly" do
79
79
  before(:each) do
80
80
  cleanup_directories_before_run
81
- @savedDir = Dir.pwd
81
+ @saved_dir = Dir.pwd
82
82
  Dir.chdir Oddb2xml::SpecCompressor
83
83
  @compressor = Oddb2xml::Compressor.new
84
84
  end
85
85
  after(:each) do
86
- Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
86
+ Dir.chdir @saved_dir if @saved_dir && File.directory?(@saved_dir)
87
87
  end
88
- it 'should fail with no contents' do
88
+ it "should fail with no contents" do
89
89
  expect(@compressor.finalize!).to eq(false)
90
90
  end
91
- it 'should fail with invalid file' do
92
- @compressor.contents << '../invalid_file'
93
- expect(@compressor.finalize!).to eq(false)
91
+ it "should fail with invalid file" do
92
+ @compressor.contents << "../invalid_file"
93
+ expect { @compressor.finalize! }.to raise_error(RuntimeError)
94
94
  end
95
95
  end
96
- context 'successfully' do
97
- context 'with tar.gz' do
96
+ context "successfully" do
97
+ context "with tar.gz" do
98
98
  before(:each) do
99
99
  cleanup_directories_before_run
100
100
  @compressor = Oddb2xml::Compressor.new
101
101
  end
102
- it_behaves_like 'any compressor'
102
+ it_behaves_like "any compressor"
103
103
  end
104
- context 'with zip' do
104
+ context "with zip" do
105
105
  before(:each) do
106
106
  cleanup_directories_before_run
107
- @savedDir = Dir.pwd
107
+ @saved_dir = Dir.pwd
108
108
  Dir.chdir Oddb2xml::SpecCompressor
109
- @compressor = Oddb2xml::Compressor.new('oddb', {:compress_ext => 'zip'})
109
+ @compressor = Oddb2xml::Compressor.new("oddb", {compress_ext: "zip"})
110
110
  end
111
111
  after(:each) do
112
- Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
112
+ Dir.chdir @saved_dir if @saved_dir && File.directory?(@saved_dir)
113
113
  end
114
- it_behaves_like 'any compressor' if true
114
+ it_behaves_like "any compressor"
115
115
  end
116
116
  end
117
117
  end
@@ -69,5 +69,6 @@
69
69
  1122069562EINF ARZNEI Urtinktur 1-10g/ml 0010040013401000000000025000005884712
70
70
  1122069639EINF ARZNEI Ceres Urtinktur spez 20ml 0023440031301000000000025000005885322
71
71
  1122069622EINF ARZNEI Ceres Urtinktur 20ml 0018870025201000000000025000005885252
72
+ 1130361821SEROCYTOL Kolon Supp 3 Stk 002275003960401B080700076800027800132
72
73
  1131770177VARILRIX Trockensub c Solv (alt) Fertspr 0.5 ml 004768006650101B080800076800058500102
73
74
  1127766692VARILRIX Trockensub c Solv Fertspr 0.5 ml 004767006650101B080800076800058500342
data/spec/data_helper.rb CHANGED
@@ -1,47 +1,47 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift File.join(File.dirname(__FILE__))
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
  module Oddb2xml
5
- # Small helper script to see, whether all files are correctly filled
6
- def Oddb2xml.fill
5
+ # Small helper script to see, whether all files are correctly filled
6
+ def self.fill
7
7
  start_keys = [
8
- 1125822801,
9
- 1125830700,
10
- 1122465312,
11
- 1120020209,
12
- 1120020244,
13
- 1130020646,
14
- 1120020652,
15
- 1130021806,
16
- 1130021976,
17
- 1130023722,
18
- 1130027447,
19
- 1130028470,
20
- 1135366964,
21
- 1122871437,
22
- 1122871443,
23
- 1122871466,
24
- 1122871472,
25
- 1132867163,
26
- 1138110429,
27
- 1130598003,
28
- 1125565072,
29
- 1126000923,
30
- 1128111222,
31
- 1128111718,
32
- 1128807890,
33
- 1117199565,
34
- 1128111611,
35
- ]
36
-
37
- gtins = GTINS_DRUGS + [ FERRO_GRADUMET_GTIN,
38
- HIRUDOID_GTIN,LANSOYL_GTIN, LEVETIRACETAM_GTIN,
39
- SOFRADEX_GTIN, THREE_TC_GTIN, ZYVOXID_GTIN]
40
- gtins.each{|gtin| Oddb2xml.check_gtin(gtin)}
8
+ 1125822801,
9
+ 1125830700,
10
+ 1122465312,
11
+ 1120020209,
12
+ 1120020244,
13
+ 1130020646,
14
+ 1120020652,
15
+ 1130021806,
16
+ 1130021976,
17
+ 1130023722,
18
+ 1130027447,
19
+ 1130028470,
20
+ 1135366964,
21
+ 1122871437,
22
+ 1122871443,
23
+ 1122871466,
24
+ 1122871472,
25
+ 1132867163,
26
+ 1138110429,
27
+ 1130598003,
28
+ 1125565072,
29
+ 1126000923,
30
+ 1128111222,
31
+ 1128111718,
32
+ 1128807890,
33
+ 1117199565,
34
+ 1128111611
35
+ ]
41
36
 
42
- ENV['LANG']= "de_CH.ISO-8859"
43
- outfile = 'spec/data/transfer.dat'
44
- FileUtils.rm_f(outfile, :verbose => true)
37
+ gtins = GTINS_DRUGS + [FERRO_GRADUMET_GTIN,
38
+ HIRUDOID_GTIN, LANSOYL_GTIN, LEVETIRACETAM_GTIN,
39
+ SOFRADEX_GTIN, THREE_TC_GTIN, ZYVOXID_GTIN]
40
+ gtins.each { |gtin| Oddb2xml.check_gtin(gtin) }
41
+
42
+ ENV["LANG"] = "de_CH.ISO-8859"
43
+ outfile = "spec/data/transfer.dat"
44
+ FileUtils.rm_f(outfile, verbose: true)
45
45
  start_keys.each do |key|
46
46
  cmd = "egrep '^#{key}' downloads/transfer.dat >> #{outfile}"
47
47
  system(cmd)
@@ -50,23 +50,21 @@ module Oddb2xml
50
50
  gtins.each do |key|
51
51
  cmd = "grep #{key} downloads/transfer.dat >> #{outfile}"
52
52
  system(cmd)
53
- iksnrs << key.to_s[4..8] if /^7680/i.match(key.to_s)
53
+ iksnrs << key.to_s[4..8] if /^7680/i.match?(key.to_s)
54
54
  end
55
55
  puts "Created #{outfile} #{File.size(outfile)} bytes"
56
- puts "Used IKSNRS are #{iksnrs.sort.uniq.join(' ')}"
56
+ puts "Used IKSNRS are #{iksnrs.sort.uniq.join(" ")}"
57
57
  end
58
-
59
- def Oddb2xml.check_gtin(gtin)
58
+
59
+ def self.check_gtin(gtin)
60
60
  files = `grep -l #{gtin} downloads/*.xml`.split("\n")
61
61
  files.each do |file|
62
- short = File.join(SpecData,File.basename(file))
63
- nrMatches = 0
64
- nrMatches = `grep -c #{gtin} #{short}`.to_i if File.exist?(short)
65
- puts "Could not find #{gtin} in #{short}" unless nrMatches > 0
62
+ short = File.join(SpecData, File.basename(file))
63
+ nr_matches = 0
64
+ nr_matches = `grep -c #{gtin} #{short}`.to_i if File.exist?(short)
65
+ puts "Could not find #{gtin} in #{short}" unless nr_matches > 0
66
66
  end
67
67
  end
68
68
  end
69
69
 
70
70
  Oddb2xml.fill
71
-
72
-
@@ -1,13 +1,13 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
1
+ require "spec_helper"
3
2
  require "rexml/document"
4
3
 
5
4
  VCR.eject_cassette # we use insert/eject around each example
6
5
 
7
6
  # not used but, as I still don't know how to generate
8
- def filter_aips_xml(filename='AipsDownload_ng.xml', ids_to_keep = [55558, 61848])
9
- puts "File #{filename} exists? #{File.exists?(filename)}"
10
- tst = %(<?xml version="1.0" encoding="utf-8"?>
7
+ def filter_aips_xml(filename = "AipsDownload_ng.xml", ids_to_keep = [55558, 61848])
8
+ puts "File #{filename} exists? #{File.exist?(filename)}"
9
+ if $VERBOSE
10
+ puts %(<?xml version="1.0" encoding="utf-8"?>
11
11
  <medicalInformations>
12
12
  <medicalInformation type="fi" version="5" lang="de" safetyRelevant="false" informationUpdate="07.2008">
13
13
  <title>Zyvoxid®</title>
@@ -16,37 +16,36 @@ def filter_aips_xml(filename='AipsDownload_ng.xml', ids_to_keep = [55558, 61848]
16
16
  <substances>Linezolid</substances>
17
17
  <authNrs>55558, 55559, 55560</authNrs>
18
18
  )
19
+ end
19
20
  @xml = IO.read(filename)
20
- ausgabe = File.open('tst.out', 'w+')
21
+ ausgabe = File.open("tst.out", "w+")
21
22
  data = {}
22
- result = MedicalInformationsContent.parse(@xml.sub(Strip_For_Sax_Machine, ''), :lazy => true)
23
+ result = MedicalInformationsContent.parse(@xml.sub(STRIP_FOR_SAX_MACHINE, ""), lazy: true)
23
24
  result.medicalInformation.each do |pac|
24
25
  lang = pac.lang.to_s
25
- next unless lang =~ /de|fr/
26
+ next unless /de|fr/.match?(lang)
26
27
  item = {}
27
- keepIt = false
28
- pac.authNrs.split(/[, ]+/).each{
29
- |id|
30
- if ids_to_keep.index(id.to_i)
31
- data[ [lang, id.to_i] ] = pac
32
- keepIt = true;
33
- ausgabe.puts
34
- break
28
+ keep_it = false
29
+ pac.authNrs.split(/[, ]+/).each { |id|
30
+ if ids_to_keep.index(id.to_i)
31
+ data[[lang, id.to_i]] = pac
32
+ keep_it = true
33
+ ausgabe.puts
34
+ break
35
35
  end
36
36
  }
37
- html = Nokogiri::HTML.fragment(pac.content.force_encoding('UTF-8'))
37
+ html = Nokogiri::HTML.fragment(pac.content.force_encoding("UTF-8"))
38
38
  item[:paragraph] = html
39
- numbers = /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/.match(html)
39
+ numbers = /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/.match(html)
40
40
  if numbers
41
- [$1, $2, $3].compact.each {
42
- |id|
43
- if ids_to_keep.index(id.to_i)
44
- data[ [lang, id.to_i] ] = pac
45
- keepIt = true;
46
- break
47
- end
48
- }
49
- puts "Must keep #{keepIt} #{pac.authNrs}"
41
+ [$1, $2, $3].compact.each { |id|
42
+ if ids_to_keep.index(id.to_i)
43
+ data[[lang, id.to_i]] = pac
44
+ keep_it = true
45
+ break
46
+ end
47
+ }
48
+ puts "Must keep #{keep_it} #{pac.authNrs}"
50
49
  end
51
50
  end
52
51
  puts data.size
@@ -54,43 +53,32 @@ def filter_aips_xml(filename='AipsDownload_ng.xml', ids_to_keep = [55558, 61848]
54
53
  end
55
54
 
56
55
  XML_VERSION_1_0 = /xml\sversion=["']1.0["']/
57
- PREP_XML = 'Preparations.xml'
58
- shared_examples_for 'any downloader' do
59
- # this takes 5 sec. by call for sleep
60
- it 'should count retry times as retrievable or not', :slow => true do
61
- expect {
62
- Array.new(3).map do
63
- Thread.new do
64
- expect(@downloader.send(:retrievable?)).to be(true)
65
- end
66
- end.map(&:join)
67
- }.to change {
68
- @downloader.instance_variable_get(:@retry_times)
69
- }.from(3).to(0)
70
- end if false # as vcr does not support threads for the moment
56
+ PREP_XML = "Preparations.xml"
57
+
58
+ shared_examples_for "any downloader" do
59
+ # nothing at the moment
71
60
  end
72
61
 
73
62
  def common_before
74
- @savedDir = Dir.pwd
63
+ @saved_dir = Dir.pwd
75
64
  cleanup_directories_before_run
76
- FileUtils.makedirs(Oddb2xml::WorkDir)
77
- Dir.chdir(Oddb2xml::WorkDir)
65
+ FileUtils.makedirs(Oddb2xml::WORK_DIR)
66
+ Dir.chdir(Oddb2xml::WORK_DIR)
78
67
  WebMock.enable!
79
- { 'https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/interactions_de_utf8.csv' => 'epha_interactions.csv',
80
- }.each do |url, file|
68
+ {"https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/interactions_de_utf8.csv" => "epha_interactions.csv"}.each do |url, file|
81
69
  inhalt = File.read(File.join(Oddb2xml::SpecData, file))
82
- stub_request(:get,url).to_return(body: inhalt)
70
+ stub_request(:get, url).to_return(body: inhalt)
83
71
  end
84
72
  end
85
73
 
86
74
  def common_after
87
- Dir.chdir(@savedDir) if @savedDir and File.directory?(@savedDir)
75
+ Dir.chdir(@saved_dir) if @saved_dir && File.directory?(@saved_dir)
88
76
  VCR.eject_cassette
89
- vcr_file = File.expand_path(File.join(Oddb2xml::SpecData, '..', 'fixtures', 'vcr_cassettes', 'oddb2xml.json'))
90
- puts "Pretty-printing #{vcr_file} exists? #{File.exists?(vcr_file)}" if $VERBOSE
91
- vcr_file_new = vcr_file.sub('.json', '.new')
77
+ vcr_file = File.expand_path(File.join(Oddb2xml::SpecData, "..", "fixtures", "vcr_cassettes", "oddb2xml.json"))
78
+ puts "Pretty-printing #{vcr_file} exists? #{File.exist?(vcr_file)}" if $VERBOSE
79
+ vcr_file_new = vcr_file.sub(".json", ".new")
92
80
  cmd = "cat #{vcr_file} | python -mjson.tool > #{vcr_file_new}"
93
- res = system(cmd)
81
+ system(cmd)
94
82
  FileUtils.mv(vcr_file_new, vcr_file)
95
83
  end
96
84
 
@@ -106,87 +94,85 @@ def zip_files(zipfile_name, input_filenames)
106
94
  end
107
95
 
108
96
  # Unzips into a specific directory
109
- def unzip_files(zipfile_name, directory=Dir.pwd)
110
- savedDir = Dir.pwd
97
+ def unzip_files(zipfile_name, directory = Dir.pwd)
98
+ saved_dir = Dir.pwd
111
99
  FileUtils.makedirs(directory)
112
100
  Dir.chdir(directory)
113
101
  Zip::File.open(zipfile_name) do |zip_file|
114
102
  # Handle entries one by one
115
103
  zip_file.each do |entry|
116
104
  # Extract to file/directory/symlink
117
- puts "downloader_spec.rb: Extracting #{entry.name} exists? #{File.exists?(entry.name)} into #{directory}"
118
- FileUtils.rm_f(entry.name, :verbose => true) if File.exists?(entry.name)
105
+ puts "downloader_spec.rb: Extracting #{entry.name} exists? #{File.exist?(entry.name)} into #{directory}"
106
+ FileUtils.rm_f(entry.name, verbose: true) if File.exist?(entry.name)
119
107
  entry.extract(entry.name)
120
108
  end
121
109
  end
122
110
  ensure
123
- Dir.chdir(savedDir)
111
+ Dir.chdir(saved_dir)
124
112
  end
125
113
 
126
-
127
114
  describe Oddb2xml::RefdataDownloader do
128
115
  include ServerMockHelper
129
116
  before(:all) do
130
117
  VCR.eject_cassette
131
118
  VCR.configure do |c|
132
119
  c.before_record(:Refdata_DE) do |i|
133
- if not /WSDL$/.match(i.request.uri) and /refdatabase.refdata.ch\/Service/.match(i.request.uri) and i.response.body.size > 1024*1024
134
- puts "#{Time.now}: #{__LINE__}: Parsing response.body (#{i.response.body.size/(1024*1024)} MB ) will take some time. URI was #{i.request.uri}"
120
+ if !/WSDL$/.match(i.request.uri) && /refdatabase.refdata.ch\/Service/.match(i.request.uri) && (i.response.body.size > 1024 * 1024)
121
+ puts "#{Time.now}: #{__LINE__}: Parsing response.body (#{i.response.body.size / (1024 * 1024)} MB ) will take some time. URI was #{i.request.uri}"
135
122
  doc = REXML::Document.new(i.response.body)
136
123
  items = doc.root.children.first.elements.first
137
- nrItems = doc.root.children.first.elements.first.elements.size
138
- puts "#{Time.now}: #{__LINE__}: Removing most of the #{nrItems} items will take some time"
139
- nrSearched = 0
140
- items.elements.each{
141
- |x|
142
- nrSearched += 1
143
- puts "#{Time.now}: #{__LINE__}: nrSearched #{nrSearched}/#{nrItems}" if nrSearched % 1000 == 0
144
- items.delete x unless x.elements['GTIN'] and Oddb2xml::GTINS_DRUGS.index(x.elements['GTIN'].text)
124
+ nr_items = doc.root.children.first.elements.first.elements.size
125
+ puts "#{Time.now}: #{__LINE__}: Removing most of the #{nr_items} items will take some time"
126
+ nr_searched = 0
127
+ items.elements.each { |x|
128
+ nr_searched += 1
129
+ puts "#{Time.now}: #{__LINE__}: nr_searched #{nr_searched}/#{nr_items}" if nr_searched % 1000 == 0
130
+ items.delete x unless x.elements["GTIN"] && Oddb2xml::GTINS_DRUGS.index(x.elements["GTIN"].text)
145
131
  }
146
132
  i.response.body = doc.to_s
147
- puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long"
148
- i.response.headers['Content-Length'] = i.response.body.size
133
+ puts "#{Time.now}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long"
134
+ i.response.headers["Content-Length"] = i.response.body.size
149
135
  end
150
136
  end
151
137
  end
152
- VCR.insert_cassette('oddb2xml', :tag => :Refdata_DE)
138
+ VCR.insert_cassette("oddb2xml", tag: :Refdata_DE)
153
139
  common_before
154
140
  end
155
141
  after(:all) do
156
142
  common_after
157
143
  end
158
- context 'Pharma' do
144
+ context "Pharma" do
159
145
  before(:all) do
160
146
  @downloader = Oddb2xml::RefdataDownloader.new({}, :pharma)
161
147
  @xml = @downloader.download
162
148
  end
163
- it_behaves_like 'any downloader'
164
- context 'when download_by is called' do
165
- it 'should parse response hash to xml' do
149
+ it_behaves_like "any downloader"
150
+ context "when download_by is called" do
151
+ it "should parse response hash to xml" do
166
152
  expect(@xml).to be_a String
167
153
  expect(@xml.length).not_to eq(0)
168
154
  expect(@xml).to match(XML_VERSION_1_0)
169
155
  end
170
- it 'should return valid xml' do
156
+ it "should return valid xml" do
171
157
  expect(@xml).to match(/PHAR/)
172
158
  expect(@xml).to match(/ITEM/)
173
159
  end
174
160
  end
175
161
  end
176
162
 
177
- context 'NonPharma' do
178
- it_behaves_like 'any downloader'
163
+ context "NonPharma" do
164
+ it_behaves_like "any downloader"
179
165
  before(:all) do
180
166
  @downloader = Oddb2xml::RefdataDownloader.new({}, :nonpharma)
181
167
  @xml = @downloader.download
182
168
  end
183
- context 'when download_by is ' do
184
- it 'should parse response hash to xml' do
169
+ context "when download_by is " do
170
+ it "should parse response hash to xml" do
185
171
  expect(@xml).to be_a String
186
172
  expect(@xml.length).not_to eq(0)
187
173
  expect(@xml).to match(XML_VERSION_1_0)
188
174
  end
189
- it 'should return valid xml' do
175
+ it "should return valid xml" do
190
176
  expect(@xml).to match(/NONPHAR/)
191
177
  expect(@xml).to match(/ITEM/)
192
178
  end
@@ -196,40 +182,45 @@ end
196
182
 
197
183
  def cleanPackungenXlsx(info)
198
184
  m = /dokumente\/liste/i.match(info.request.uri)
199
- puts "#{Time.now}: #{__LINE__} SwissmedicDownloader #{info.request.uri} #{m[1]} (#{info.response.body.size/(1024*1024)} MB )."
185
+ puts "#{Time.now}: #{__LINE__} SwissmedicDownloader #{info.request.uri} #{m[1]} (#{info.response.body.size / (1024 * 1024)} MB )."
200
186
  return unless m
201
187
  name = nil
202
- name = 'packungen' if /zugelasseneverpackungen/.match(info.request.uri)
203
- name = 'orphan' if /zugelasseneverpackungen/.match(info.request.uri)
204
- swissmedic_dir = File.join(Oddb2xml::WorkDir, 'swissmedic')
188
+ name = "packungen" if /zugelasseneverpackungen/.match?(info.request.uri)
189
+ name = "orphan" if /zugelasseneverpackungen/.match?(info.request.uri)
190
+ swissmedic_dir = File.join(Oddb2xml::WORK_DIR, "swissmedic")
205
191
  FileUtils.makedirs(swissmedic_dir)
206
- xlsx_name = File.join(swissmedic_dir, name + '.xlsx')
207
- if /Packungen/i.match(xlsx_name)
208
- FileUtils.rm(xlsx_name, :verbose => false) if File.exists?(xlsx_name)
209
- File.open(xlsx_name, 'wb+') { |f| f.write(info.response.body) }
210
- FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData, 'swissmedic_package_downloaded.xlsx'), :verbose => true, :preserve => true)
192
+ xlsx_name = File.join(swissmedic_dir, name + ".xlsx")
193
+ if /Packungen/i.match?(xlsx_name)
194
+ FileUtils.rm(xlsx_name, verbose: false) if File.exist?(xlsx_name)
195
+ File.open(xlsx_name, "wb+") { |f| f.write(info.response.body) }
196
+ FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData, "swissmedic_package_downloaded.xlsx"), verbose: true, preserve: true)
211
197
  puts "#{Time.now}: #{__LINE__}: Openening saved #{xlsx_name} (#{File.size(xlsx_name)} bytes) will take some time. URI was #{info.request.uri}"
212
198
  workbook = RubyXL::Parser.parse(xlsx_name)
213
199
  worksheet = workbook[0]
214
200
  drugs = []
215
- Oddb2xml::GTINS_DRUGS.each{ |x| next unless x.to_s.size == 13; drugs << [x.to_s[4..8].to_i, x.to_s[9..11].to_i] };
216
- idx = 6; to_delete = []
201
+ Oddb2xml::GTINS_DRUGS.each do |x|
202
+ next unless x.to_s.size == 13
203
+ drugs << [x.to_s[4..8].to_i, x.to_s[9..11].to_i]
204
+ end
205
+ idx = 6
206
+ to_delete = []
217
207
  puts "#{Time.now}: Finding items to delete will take some time"
218
- while (worksheet.sheet_data[idx])
219
- idx += 1
220
- next unless worksheet.sheet_data[idx-1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:iksnr)]
221
- to_delete << (idx-1) unless drugs.find{ |x| x[0]== worksheet.sheet_data[idx-1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:iksnr)].value.to_i and
222
- x[1]== worksheet.sheet_data[idx-1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:ikscd)].value.to_i
223
- }
208
+ while worksheet.sheet_data[idx]
209
+ idx += 1
210
+ next unless worksheet.sheet_data[idx - 1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:iksnr)]
211
+ to_delete << (idx - 1) unless drugs.find { |x|
212
+ (x[0] == worksheet.sheet_data[idx - 1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:iksnr)].value.to_i) &&
213
+ (x[1] == worksheet.sheet_data[idx - 1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:ikscd)].value.to_i)
214
+ }
224
215
  end
225
216
  if to_delete.size > 0
226
217
  puts "#{Time.now}: Deleting #{to_delete.size} of the #{idx} items will take some time"
227
- to_delete.reverse.each{ |row_id| worksheet.delete_row(row_id) }
218
+ to_delete.reverse_each { |row_id| worksheet.delete_row(row_id) }
228
219
  workbook.write(xlsx_name)
229
- FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData, 'swissmedic_package_shortened.xlsx'), :verbose => true, :preserve => true)
220
+ FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData, "swissmedic_package_shortened.xlsx"), verbose: true, preserve: true)
230
221
  info.response.body = IO.binread(xlsx_name)
231
- info.response.headers['Content-Length'] = info.response.body.size
232
- puts "#{Time.now}: response.body is now #{info.response.body.size/(1024*1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
222
+ info.response.headers["Content-Length"] = info.response.body.size
223
+ puts "#{Time.now}: response.body is now #{info.response.body.size / (1024 * 1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
233
224
  end
234
225
  end
235
226
  end
@@ -240,79 +231,73 @@ describe Oddb2xml::SwissmedicDownloader do
240
231
  mock_downloads
241
232
  VCR.configure do |c|
242
233
  c.before_record(:swissmedic) do |i|
243
- config = c
244
- info = i
245
- begin
246
- if i.response.headers['Content-Disposition'] and /www.swissmedic.ch/.match(i.request.uri) and i.response.body.size > 1024*1024
234
+ if i.response.headers["Content-Disposition"] && /www.swissmedic.ch/.match(i.request.uri) && (i.response.body.size > 1024 * 1024)
247
235
  cleanPackungenXlsx(i)
248
236
  end
249
- rescue => error
250
- require 'pry'; binding.pry
251
- end
237
+ rescue => error
238
+ puts error if $VERBOSE
239
+ # require "pry"; binding.pry
252
240
  end
253
241
  end
254
242
  end
255
- # 2015-06-10 18:54:40 UTC: SwissmedicDownloader attachment; filename="Zugelassene_Packungen_310515.xlsx" (785630 bytes). URI was https://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdHx7hGym162epYbg2c_JjKbNoKSn6A--&lang=de
243
+ # 2015-06-10 18:54:40 UTC: SwissmedicDownloader attachment; filename="Zugelassene_Packungen_310515.xlsx" (785630 bytes). URI was https://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdHx7hGym162epYbg2c_JjKbNoKSn6A--&lang=de
256
244
 
257
- context 'orphan' do
245
+ context "orphan" do
258
246
  before(:each) do
259
247
  VCR.configure do |c|
260
248
  c.before_record(:swissmedic) do |i|
261
- config = c
262
- info = i
263
- begin
264
- if i.response.headers['Content-Disposition'] and /www.swissmedic.ch/.match(i.request.uri) and i.response.body.size > 1024*1024
249
+ if i.response.headers["Content-Disposition"] && /www.swissmedic.ch/.match(i.request.uri) && (i.response.body.size > 1024 * 1024)
265
250
  cleanPackungenXlsx(i)
266
251
  end
267
- rescue => error
268
- require 'pry'; binding.pry
269
- end
252
+ rescue => error
253
+ puts error if $VERBOSE
254
+ # require "pry"; binding.pry
270
255
  end
271
256
  end
272
257
  VCR.eject_cassette
273
- VCR.insert_cassette('oddb2xml', :tag => :swissmedic, :exclusive => false)
258
+ VCR.insert_cassette("oddb2xml", tag: :swissmedic, exclusive: false)
274
259
  common_before
275
260
  @downloader = Oddb2xml::SwissmedicDownloader.new(:orphan)
276
261
  end
277
- after(:each) do common_after end
278
- it_behaves_like 'any downloader'
279
- context 'download_by for orphan xls' do
262
+ after(:each) { common_after }
263
+ it_behaves_like "any downloader"
264
+ context "download_by for orphan xls" do
280
265
  let(:bin) {
281
266
  @downloader.download
282
267
  }
283
- it 'should return valid Binary-String' do
268
+ it "should return valid Binary-String" do
284
269
  # unless [:orphan, :package].index(@downloader.type)
285
- expect(bin).to be_a String
286
- expect(bin.bytes).not_to be nil
270
+ expect(bin).to be_a String
271
+ expect(bin.bytes).not_to be nil
287
272
  # end
288
273
  end
289
- it 'should clean up current directory' do
274
+ it "should clean up current directory" do
290
275
  unless [:orphan, :package].index(@downloader.type)
291
276
  expect { bin }.not_to raise_error
292
- expect(File.exist?('oddb_orphan.xls')).to eq(false)
277
+ expect(File.exist?("oddb_orphan.xls")).to eq(false)
293
278
  end
294
279
  end
295
- it 'should not save into the download directory' do
296
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'oddb_orphan.xls'))).to eq(false)
280
+ it "should not save into the download directory" do
281
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "oddb_orphan.xls"))).to eq(false)
297
282
  end
298
283
  end
299
284
  end
300
- context 'package' do
285
+ context "package" do
301
286
  before(:each) do
302
287
  VCR.eject_cassette
303
- VCR.insert_cassette('oddb2xml', :tag => :swissmedic, :exclusive => false)
288
+ VCR.insert_cassette("oddb2xml", tag: :swissmedic, exclusive: false)
304
289
  common_before
305
290
  @downloader = Oddb2xml::SwissmedicDownloader.new(:package)
306
291
  @bin = @downloader.download
307
292
  end
308
- after(:each) do common_after end
309
- context 'download_by for package xls' do
310
- it 'should return valid Binary-String' do
293
+ after(:each) { common_after }
294
+ context "download_by for package xls" do
295
+ it "should return valid Binary-String" do
311
296
  expect(@bin).to be_a String
312
297
  expect(@bin.bytes).not_to be nil
313
298
  end
314
- it 'should save into the download directory' do
315
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'swissmedic_package.xlsx'))).to eq(true)
299
+ it "should save into the download directory" do
300
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "swissmedic_package.xlsx"))).to eq(true)
316
301
  end
317
302
  end
318
303
  end
@@ -327,59 +312,59 @@ describe Oddb2xml::EphaDownloader do
327
312
  Oddb2xml.add_epha_changes_for_ATC(1, 3, force_run: true)
328
313
  @csv = @downloader.download
329
314
  }
330
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'epha_interactions.csv'))).to eq(true)
315
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "epha_interactions.csv"))).to eq(true)
331
316
  end
332
317
  after(:all) do
333
318
  common_after
334
319
  end
335
320
 
336
- it_behaves_like 'any downloader'
321
+ it_behaves_like "any downloader"
337
322
 
338
- context 'when download is called' do
339
- let(:csv) { @csv }
340
- it 'should read csv as String' do
323
+ context "when download is called" do
324
+ let(:csv) { @csv }
325
+ it "should read csv as String" do
341
326
  expect(csv).to be_a String
342
327
  expect(csv.bytes).not_to be nil
343
328
  end
344
- it 'should clean up current directory' do
345
- expect(File.exist?('epha_interactions.csv')).to eq(false)
329
+ it "should clean up current directory" do
330
+ expect(File.exist?("epha_interactions.csv")).to eq(false)
346
331
  end
347
- it 'should save under download' do
348
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'epha_interactions.csv'))).to eq(true)
332
+ it "should save under download" do
333
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "epha_interactions.csv"))).to eq(true)
349
334
  end
350
335
  end
351
336
  end
352
337
 
353
338
  describe Oddb2xml::BagXmlDownloader do
354
339
  include ServerMockHelper
355
- before(:all) do VCR.eject_cassette end
340
+ before(:all) { VCR.eject_cassette }
356
341
  before(:all) {
357
342
  VCR.configure do |c|
358
343
  c.before_record(:bag_xml) do |i|
359
- if i.response.headers['Content-Disposition'] and /XMLPublications.zip/.match(i.request.uri)
360
- bag_dir = File.join(Oddb2xml::WorkDir, 'bag')
361
- FileUtils.makedirs(Oddb2xml::WorkDir)
362
- tmp_zip = File.join(Oddb2xml::WorkDir, 'XMLPublications.zip')
363
- File.open(tmp_zip, 'wb+') { |f| f.write(i.response.body) }
344
+ if i.response.headers["Content-Disposition"] && /XMLPublications.zip/.match(i.request.uri)
345
+ bag_dir = File.join(Oddb2xml::WORK_DIR, "bag")
346
+ FileUtils.makedirs(Oddb2xml::WORK_DIR)
347
+ tmp_zip = File.join(Oddb2xml::WORK_DIR, "XMLPublications.zip")
348
+ File.open(tmp_zip, "wb+") { |f| f.write(i.response.body) }
364
349
  unzip_files(tmp_zip, bag_dir)
365
350
  bag_tmp = File.join(bag_dir, PREP_XML)
366
351
  puts "#{Time.now}: #{__LINE__}: Parsing #{File.size(bag_tmp)} (#{File.size(bag_tmp)} bytes) will take some time. URI was #{i.request.uri}"
367
352
  doc = REXML::Document.new(File.read(bag_tmp))
368
353
  items = doc.root.elements
369
354
  puts "#{Time.now}: Removing most of the #{items.size} items will take some time"
370
- items.each{ |x| items.delete x unless Oddb2xml::GTINS_DRUGS.index(x.elements['Packs/Pack/GTIN'].text); }
371
- File.open(bag_tmp, 'wb+') { |f| f.write(doc.to_s.gsub(/\n\s+\n/, "\n")) }
355
+ items.each { |x| items.delete x unless Oddb2xml::GTINS_DRUGS.index(x.elements["Packs/Pack/GTIN"].text); }
356
+ File.open(bag_tmp, "wb+") { |f| f.write(doc.to_s.gsub(/\n\s+\n/, "\n")) }
372
357
  puts "Saved #{bag_tmp} (#{File.size(tmp_zip)} bytes)"
373
358
  zip_files(tmp_zip, Dir.glob("#{bag_dir}/*"))
374
359
  puts "Saved #{tmp_zip} (#{File.size(tmp_zip)} bytes)"
375
360
  i.response.body = IO.binread(tmp_zip)
376
- i.response.headers['Content-Length'] = i.response.body.size
377
- puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
361
+ i.response.headers["Content-Length"] = i.response.body.size
362
+ puts "#{Time.now}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
378
363
  end
379
364
  end
380
365
  end
381
- VCR.eject_cassette
382
- VCR.use_cassette('oddb2xml', :tag => :bag_xml) do
366
+ VCR.eject_cassette
367
+ VCR.use_cassette("oddb2xml", tag: :bag_xml) do
383
368
  @downloader = Oddb2xml::BagXmlDownloader.new
384
369
  end
385
370
  common_before
@@ -388,19 +373,19 @@ describe Oddb2xml::BagXmlDownloader do
388
373
  common_after
389
374
  end
390
375
 
391
- it_behaves_like 'any downloader'
392
- context 'when download is called' do
376
+ it_behaves_like "any downloader"
377
+ context "when download is called" do
393
378
  let(:xml) {
394
379
  VCR.eject_cassette
395
- VCR.use_cassette('oddb2xml', :tag => :bag_xml) do
380
+ VCR.use_cassette("oddb2xml", tag: :bag_xml) do
396
381
  @downloader.download
397
382
  end
398
383
  }
399
- it 'should parse zip to string' do
384
+ it "should parse zip to string" do
400
385
  expect(xml).to be_a String
401
386
  expect(xml.length).not_to eq(0)
402
387
  end
403
- it 'should return valid xml' do
388
+ it "should return valid xml" do
404
389
  expect(xml).to match(XML_VERSION_1_0)
405
390
  expect(xml).to match(/Preparations/)
406
391
  expect(xml).to match(/DescriptionDe/)
@@ -410,174 +395,177 @@ end
410
395
 
411
396
  describe Oddb2xml::LppvDownloader do
412
397
  include ServerMockHelper
413
- before(:all) do VCR.eject_cassette end
398
+ before(:all) { VCR.eject_cassette }
414
399
  before(:all) do
415
- VCR.insert_cassette('oddb2xml', :tag => :lppv)
400
+ VCR.insert_cassette("oddb2xml", tag: :lppv)
416
401
  common_before
417
402
  @downloader = Oddb2xml::LppvDownloader.new
418
403
  @text = @downloader.download
419
404
  end
420
- after(:each) do common_after end
405
+ after(:each) { common_after }
421
406
 
422
- it_behaves_like 'any downloader'
423
- context 'when download is called' do
407
+ it_behaves_like "any downloader"
408
+ context "when download is called" do
424
409
  let(:txt) { @downloader.download }
425
- it 'should read txt as String' do
410
+ it "should read txt as String" do
426
411
  expect(@text).to be_a String
427
412
  expect(@text.bytes).not_to be nil
428
413
  end
429
414
  end
430
415
  end
431
416
 
432
- describe Oddb2xml::MigelDownloader do
433
- include ServerMockHelper
434
- before(:all) do VCR.eject_cassette end
435
- before(:each) do
436
- @downloader = Oddb2xml::MigelDownloader.new
437
- VCR.insert_cassette('oddb2xml', :tag => :migel)
438
- common_before
439
- @downloader.download
440
- end
441
- after(:each) do common_after end
442
-
443
- it_behaves_like 'any downloader'
444
- context 'when download is called' do
445
- let(:bin) { @downloader.download }
446
- it 'should read xls as Binary-String' do
447
- expect(bin).to be_a String
448
- expect(bin.bytes).not_to be nil
417
+ unless SKIP_MIGEL_DOWNLOADER
418
+ describe Oddb2xml::MigelDownloader do
419
+ include ServerMockHelper
420
+ before(:all) { VCR.eject_cassette }
421
+ before(:each) do
422
+ @downloader = Oddb2xml::MigelDownloader.new
423
+ VCR.insert_cassette("oddb2xml", tag: :migel)
424
+ common_before
425
+ @downloader.download
449
426
  end
450
- it 'should clean up current directory' do
451
- expect { bin }.not_to raise_error
452
- expect(File.exist?('oddb2xml_files_nonpharma.txt')).to eq(false)
427
+ after(:each) { common_after }
428
+
429
+ it_behaves_like "any downloader"
430
+ context "when download is called" do
431
+ let(:bin) { @downloader.download }
432
+ it "should read xls as Binary-String" do
433
+ expect(bin).to be_a String
434
+ expect(bin.bytes).not_to be nil
435
+ end
436
+ it "should clean up current directory" do
437
+ expect { bin }.not_to raise_error
438
+ expect(File.exist?("oddb2xml_files_nonpharma.txt")).to eq(false)
439
+ end
453
440
  end
454
441
  end
455
- end unless SkipMigelDownloader
442
+ end
456
443
 
457
444
  describe Oddb2xml::ZurroseDownloader do
458
445
  include ServerMockHelper
459
- before(:all) do VCR.eject_cassette end
446
+ before(:all) { VCR.eject_cassette }
460
447
  before(:each) do
461
448
  VCR.configure do |c|
462
449
  c.before_record(:zurrose) do |i|
463
- if /pillbox/i.match(i.request.uri)
450
+ if /pillbox/i.match?(i.request.uri)
464
451
  puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri}"
465
- tmp_zip = File.join(Oddb2xml::SpecData, 'vcr', 'transfer.zip')
452
+ tmp_zip = File.join(Oddb2xml::SpecData, "vcr", "transfer.zip")
466
453
  i.response.body = IO.binread(tmp_zip)
467
- i.response.headers['Content-Length'] = i.response.body.size
454
+ i.response.headers["Content-Length"] = i.response.body.size
468
455
  end
469
456
  end
470
457
  end
471
- VCR.insert_cassette('oddb2xml', :tag => :zurrose)
458
+ VCR.insert_cassette("oddb2xml", tag: :zurrose)
472
459
  @downloader = Oddb2xml::ZurroseDownloader.new
473
460
  common_before
474
461
  @downloader.download
475
462
  end
476
- after(:each) do common_after end
463
+ after(:each) { common_after }
477
464
 
478
- it_behaves_like 'any downloader'
479
- context 'when download is called' do
465
+ it_behaves_like "any downloader"
466
+ context "when download is called" do
480
467
  let(:dat) { @downloader.download }
481
- it 'should read dat as String' do
468
+ it "should read dat as String" do
482
469
  expect(dat).to be_a String
483
470
  expect(dat.bytes).not_to be nil
484
471
  end
485
- it 'should clean up current directory' do
472
+ it "should clean up current directory" do
486
473
  expect { dat }.not_to raise_error
487
- expect(File.exist?('transfer.dat')).to eq(false)
488
- expect(File.exist?('oddb2xml_zurrose_transfer.dat')).to eq(false)
489
- expect(File.exist?('transfer.zip')).to eq(false)
474
+ expect(File.exist?("transfer.dat")).to eq(false)
475
+ expect(File.exist?("oddb2xml_zurrose_transfer.dat")).to eq(false)
476
+ expect(File.exist?("transfer.zip")).to eq(false)
490
477
  end
491
- it 'should save into the download directory' do
492
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'transfer.zip'))).to eq(true)
493
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'transfer.dat'))).to eq(true)
478
+ it "should save into the download directory" do
479
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "transfer.zip"))).to eq(true)
480
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "transfer.dat"))).to eq(true)
494
481
  end
495
482
  end
496
483
  end
497
484
 
498
485
  describe Oddb2xml::MedregbmDownloader do
499
486
  include ServerMockHelper
500
- before(:all) do VCR.eject_cassette end
487
+ before(:all) { VCR.eject_cassette }
501
488
  before(:each) do
502
489
  VCR.configure do |c|
503
490
  c.before_record(:medreg) do |i|
504
- if /medregbm.admin.ch/i.match(i.request.uri)
505
- puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} containing #{i.response.body.size/(1024*1024)} MB "
491
+ if /medregbm.admin.ch/i.match?(i.request.uri)
492
+ puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} containing #{i.response.body.size / (1024 * 1024)} MB "
506
493
  begin
507
- medreg_dir = File.join(Oddb2xml::WorkDir, 'medreg')
494
+ medreg_dir = File.join(Oddb2xml::WORK_DIR, "medreg")
508
495
  FileUtils.makedirs(medreg_dir)
509
- xlsx_name = File.join(medreg_dir, /ListBetrieb/.match(i.request.uri) ? 'Betriebe.xlsx' : 'Personen.xlsx')
510
- File.open(xlsx_name, 'wb+') { |f| f.write(i.response.body) }
496
+ xlsx_name = File.join(medreg_dir, /ListBetrieb/.match?(i.request.uri) ? "Betriebe.xlsx" : "Personen.xlsx")
497
+ File.open(xlsx_name, "wb+") { |f| f.write(i.response.body) }
511
498
  puts "#{Time.now}: Openening saved #{xlsx_name} (#{File.size(xlsx_name)} bytes) will take some time. URI was #{i.request.uri}"
512
499
  workbook = RubyXL::Parser.parse(xlsx_name)
513
500
  worksheet = workbook[0]
514
- idx = 1; to_delete = []
515
- while (worksheet.sheet_data[idx])
501
+ idx = 1
502
+ to_delete = []
503
+ while worksheet.sheet_data[idx]
516
504
  idx += 1
517
- next unless worksheet.sheet_data[idx-1][0]
518
- to_delete << (idx-1) unless Oddb2xml::GTINS_MEDREG.index(worksheet.sheet_data[idx-1][0].value.to_i)
505
+ next unless worksheet.sheet_data[idx - 1][0]
506
+ to_delete << (idx - 1) unless Oddb2xml::GTINS_MEDREG.index(worksheet.sheet_data[idx - 1][0].value.to_i)
519
507
  end
520
508
  if to_delete.size > 0
521
509
  puts "#{Time.now}: Deleting #{to_delete.size} of the #{idx} items will take some time"
522
- to_delete.reverse.each{ |row_id| worksheet.delete_row(row_id) }
510
+ to_delete.reverse_each { |row_id| worksheet.delete_row(row_id) }
523
511
  workbook.write(xlsx_name)
524
512
  i.response.body = IO.binread(xlsx_name)
525
- i.response.headers['Content-Length'] = i.response.body.size
526
- puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
513
+ i.response.headers["Content-Length"] = i.response.body.size
514
+ puts "#{Time.now}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
527
515
  end
528
516
  rescue
529
517
  puts "Creating empty content, as I am unable to parse the XLSX file"
530
518
  i.response.body = ""
531
- i.response.headers['Content-Length'] = i.response.body.size
519
+ i.response.headers["Content-Length"] = i.response.body.size
532
520
  end
533
521
  end
534
522
  end
535
523
  end
536
524
  common_before
537
525
  end
538
- after(:each) do common_after end
526
+ after(:each) { common_after }
539
527
 
540
- context 'betrieb' do
528
+ context "betrieb" do
541
529
  before(:each) do
542
530
  VCR.eject_cassette
543
- VCR.insert_cassette('oddb2xml', :tag => :medreg)
531
+ VCR.insert_cassette("oddb2xml", tag: :medreg)
544
532
  @downloader = Oddb2xml::MedregbmDownloader.new(:company)
545
533
  @downloader.download
546
534
  end
547
- after(:each) do common_after end
548
- it_behaves_like 'any downloader'
549
- context 'download betrieb txt' do
535
+ after(:each) { common_after }
536
+ it_behaves_like "any downloader"
537
+ context "download betrieb txt" do
550
538
  let(:txt) { @downloader.download }
551
- it 'should return valid String' do
539
+ it "should return valid String" do
552
540
  expect(txt).to be_a String
553
541
  expect(txt.bytes).not_to be nil
554
542
  end
555
- it 'should clean up current directory' do
543
+ it "should clean up current directory" do
556
544
  expect { txt }.not_to raise_error
557
- expect(File.exist?('oddb_company.xls')).to eq(false)
545
+ expect(File.exist?("oddb_company.xls")).to eq(false)
558
546
  end
559
547
  end
560
548
  end
561
549
 
562
- context 'person' do
550
+ context "person" do
563
551
  before(:each) do
564
552
  VCR.eject_cassette
565
- VCR.insert_cassette('oddb2xml', :tag => :medreg)
553
+ VCR.insert_cassette("oddb2xml", tag: :medreg)
566
554
  @downloader = Oddb2xml::MedregbmDownloader.new(:person)
567
555
  end
568
- after(:each) do common_after end
569
- context 'download person txt' do
556
+ after(:each) { common_after }
557
+ context "download person txt" do
570
558
  let(:txt) {
571
559
  # this downloads a xlsx file (2.5MB), where we should keep only the first few lines
572
560
  @downloader.download
573
561
  }
574
- it 'should return valid String' do
562
+ it "should return valid String" do
575
563
  expect(txt).to be_a String
576
564
  expect(txt.bytes).not_to be nil
577
565
  end
578
- it 'should clean up current directory' do
566
+ it "should clean up current directory" do
579
567
  expect { txt }.not_to raise_error
580
- expect(File.exist?('oddb_person.xls')).to eq(false)
568
+ expect(File.exist?("oddb_person.xls")).to eq(false)
581
569
  end
582
570
  end
583
571
  end
@@ -588,49 +576,48 @@ describe Oddb2xml::SwissmedicInfoDownloader do
588
576
  before(:all) do
589
577
  VCR.configure do |c|
590
578
  c.before_record(:swissmedicInfo) do |i|
591
- puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} returning #{i.response.body.size/(1024*1024)} MB "
592
- if i.response.headers['Content-Disposition']
593
- m = /filename=([^\d]+)/.match(i.response.headers['Content-Disposition'][0])
594
- if m
595
- name = m[1].chomp('_')
596
- if /AipsDownload/i.match(name)
597
- # we replace this by manually reduced xml file from spec/data
598
- # As we only use to create the fachinfo, we don't need many elements
599
- tmp_zip = File.join(Oddb2xml::SpecData, 'AipsDownload.zip')
600
- i.response.body = IO.binread(tmp_zip)
601
- i.response.headers['Content-Length'] = i.response.body.size
602
- puts "#{Time.now}: #{__LINE__}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
579
+ puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} returning #{i.response.body.size / (1024 * 1024)} MB"
580
+ if i.response.headers["Content-Disposition"]
581
+ m = /filename=([^\d]+)/.match(i.response.headers["Content-Disposition"][0])
582
+ if m
583
+ name = m[1].chomp("_")
584
+ if /AipsDownload/i.match?(name)
585
+ # we replace this by manually reduced xml file from spec/data
586
+ # As we only use to create the fachinfo, we don't need many elements
587
+ tmp_zip = File.join(Oddb2xml::SpecData, "AipsDownload.zip")
588
+ i.response.body = IO.binread(tmp_zip)
589
+ i.response.headers["Content-Length"] = i.response.body.size
590
+ puts "#{Time.now}: #{__LINE__}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
591
+ end
603
592
  end
604
593
  end
605
594
  end
606
595
  end
607
- end
608
596
  VCR.eject_cassette
609
- VCR.insert_cassette('oddb2xml', :tag => :swissmedicInfo)
597
+ VCR.insert_cassette("oddb2xml", tag: :swissmedicInfo)
610
598
  common_before
611
599
  @downloader = Oddb2xml::SwissmedicInfoDownloader.new
612
600
  @downloader.download
613
601
  end
614
- after(:all) do common_after end
615
- it_behaves_like 'any downloader'
616
- context 'when download is called' do
617
- let(:xml) { @downloader.download }
618
- it 'should parse zip to String' do
602
+ after(:all) { common_after }
603
+ it_behaves_like "any downloader"
604
+ context "when download is called" do
605
+ let(:xml) { @downloader.download }
606
+ it "should parse zip to String" do
619
607
  expect(xml).to be_a String
620
608
  expect(xml.length).not_to eq(0)
621
609
  end
622
- it 'should return valid xml' do
610
+ it "should return valid xml" do
623
611
  expect(xml).to match(XML_VERSION_1_0)
624
612
  expect(xml).to match(/medicalInformations/)
625
613
  expect(xml).to match(/content/)
626
614
  end
627
- it 'should clean up current directory' do
615
+ it "should clean up current directory" do
628
616
  expect { xml }.not_to raise_error
629
- expect(File.exist?('swissmedic_info.zip')).to eq(false)
617
+ expect(File.exist?("swissmedic_info.zip")).to eq(false)
630
618
  end
631
- it 'should save into the download directory' do
632
- expect(File.exist?(File.join(Oddb2xml::Downloads, 'swissmedic_info.zip'))).to eq(true)
619
+ it "should save into the download directory" do
620
+ expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "swissmedic_info.zip"))).to eq(true)
633
621
  end
634
622
  end
635
623
  end
636
-