oddb2xml 1.6.2 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -14,3 +14,7 @@ group :development do
14
14
  gem 'hoe', '>= 3.4'
15
15
  gem 'rdoc'
16
16
  end
17
+
18
+ group :debugger do
19
+ gem 'pry-debugger'
20
+ end
@@ -1,3 +1,9 @@
1
+ === 1.6.3 / 10.12.2013
2
+
3
+ * Added more specs. Use ean to find price-info if no pharmacode
4
+ * Fix running specs
5
+ * Added skip-download for debugging
6
+
1
7
  === 1.6.2 / 09.12.2013
2
8
 
3
9
  * Read article with no pharmacode from BAG.xml Preparation.xml
@@ -13,6 +13,7 @@ def help
13
13
  #$0 ver.#{Oddb2xml::VERSION}
14
14
  Usage:
15
15
  oddb2xml [option]
16
+ produced files are found under data
16
17
  -a T, --append=T Additional target. T, only 'nonpharma' is available.
17
18
  -c F, --compress=F Compress format F. {tar.gz|zip}
18
19
  -f F, --format=F File format F, default is xml. {xml|dat}
@@ -24,6 +25,10 @@ Usage:
24
25
  -t S, --tag-suffix=S XML tag suffix S. Default is none. [A-z0-9]
25
26
  If S is given, it is also used as prefix of filename.
26
27
  -x N, --context=N context N {product|address}. product is default.
28
+
29
+ For debugging purposes
30
+ --skip-download skips downloading files it the file is already under data/downloads.
31
+ Downloaded files are saved under data/downloads
27
32
  -h, --help Show this help message.
28
33
  EOS
29
34
  end
@@ -38,6 +43,7 @@ opts = {
38
43
  :tag_suffix => nil,
39
44
  :debug => false,
40
45
  :ean14 => false,
46
+ :skip_download=> false,
41
47
  }
42
48
 
43
49
  parser.on('-a v', '--append v', /^nonpharma$/) {|v| opts[:nonpharma] = true }
@@ -48,7 +54,7 @@ parser.on('-i v', '--include v', /^ean14$/) {|v| opts[:ean14] = true }
48
54
  parser.on('-t v', '--tag-suffix v', /^[A-z0-9]*$/i) {|v| opts[:tag_suffix] = v.upcase }
49
55
  parser.on('-x v', '--context v', /^addr(ess)*$/i){|v| opts[:address] = true }
50
56
  parser.on('-p v', '--price v', /^zurrose$/) {|v| opts[:price] = v.intern }
51
- #parser.on('--debug') {|v| opts[:debug] = true }
57
+ parser.on('--skip-download') {|v| opts[:skip_download] = true }
52
58
  parser.on_tail('-h', '--help') { puts help; exit }
53
59
 
54
60
  args = ARGV.dup
@@ -81,6 +87,6 @@ then you will not see anymore warnings
81
87
  end
82
88
  ui.run
83
89
  rescue Interrupt
84
- puts
85
90
  exit
86
91
  end
92
+ puts "#{Time.now}: #{__LINE__} done"; $stdout.sync
@@ -22,7 +22,8 @@ module Oddb2xml
22
22
  :infos, :packs, :prices,
23
23
  :ean14, :tag_suffix,
24
24
  :companies, :people
25
- def initialize
25
+ def initialize(args = {})
26
+ @options = args
26
27
  @subject = nil
27
28
  @index = {}
28
29
  @items = {}
@@ -390,8 +391,12 @@ module Oddb2xml
390
391
  seq = obj[:seq]
391
392
  length += 1
392
393
  xml.PRD('DT' => '') {
393
- xml.GTIN obj[:ean].to_s
394
- ppac = ((_ppac = @packs[obj[:ean].to_s[4..11].intern] and !_ppac[:is_tier]) ? _ppac : {})
394
+ ean = obj[:ean].to_s
395
+ xml.GTIN ean
396
+ ppac = ((_ppac = @packs[ean[4..11].intern] and !_ppac[:is_tier]) ? _ppac : {})
397
+ unless ppac
398
+ ppac = @packs.find{|pac| pac.ean == ean }.first
399
+ end
395
400
  xml.PRODNO ppac[:prodno] if ppac[:prodno] and !ppac[:prodno].empty?
396
401
  if seq
397
402
  %w[de fr].each do |l|
@@ -537,8 +542,12 @@ module Oddb2xml
537
542
  fr_idx = obj[:fr][i] # swissindex FR
538
543
  pac,no8 = nil,de_idx[:ean][4..11] # BAG-XML(SL/LS)
539
544
  ppac = nil # Packungen
545
+ ean = de_idx[:ean]
540
546
  if obj[:seq]
541
547
  pac = obj[:seq][:packages][de_idx[:pharmacode]]
548
+ pac = obj[:seq][:packages][ean] unless pac
549
+ else
550
+ pac = @items[ean][:packages][ean] if @items and @items[ean]
542
551
  end
543
552
  if no8
544
553
  ppac = ((_ppac = @packs[no8.intern] and !_ppac[:is_tier]) ? _ppac : nil)
@@ -573,7 +582,7 @@ module Oddb2xml
573
582
  if de_idx
574
583
  xml.SALECD(de_idx[:status].empty? ? 'N' : de_idx[:status])
575
584
  end
576
- if pac
585
+ if pac and pac[:limitation_points]
577
586
  #xml.INSLIM
578
587
  xml.LIMPTS pac[:limitation_points] unless pac[:limitation_points].empty?
579
588
  end
@@ -656,7 +665,7 @@ module Oddb2xml
656
665
  #xml.LINENO
657
666
  #xml.NOUNITS
658
667
  #}
659
- if pac
668
+ if pac and pac[:prices]
660
669
  pac[:prices].each_pair do |key, price|
661
670
  xml.ARTPRI {
662
671
  xml.VDAT price[:valid_date] unless price[:valid_date].empty?
@@ -956,6 +965,7 @@ module Oddb2xml
956
965
  pac,no8 = nil,nil
957
966
  if obj[:seq]
958
967
  pac = obj[:seq][:packages][idx[:pharmacode]]
968
+ pac = obj[:seq][:packages][idx[:ean]] unless pac
959
969
  end
960
970
  # :swissmedic_numbers
961
971
  if pac
@@ -5,6 +5,7 @@ require 'oddb2xml/builder'
5
5
  require 'oddb2xml/downloader'
6
6
  require 'oddb2xml/extractor'
7
7
  require 'oddb2xml/compressor'
8
+ require 'oddb2xml/util'
8
9
 
9
10
  module Oddb2xml
10
11
  class Cli
@@ -14,6 +15,7 @@ module Oddb2xml
14
15
  LANGUAGES = %w[DE FR] # EN does not exist
15
16
  def initialize(args)
16
17
  @options = args
18
+ Oddb2xml.save_options(@options)
17
19
  @mutex = Mutex.new
18
20
  # product
19
21
  @items = {} # Items from Preparations.xml in BAG
@@ -88,7 +90,7 @@ module Oddb2xml
88
90
  def build
89
91
  begin
90
92
  files.each_pair do |sbj, file|
91
- builder = Builder.new do |builder|
93
+ builder = Builder.new(@options) do |builder|
92
94
  if @options[:address]
93
95
  builder.subject = sbj
94
96
  builder.companies = @companies
@@ -143,7 +145,7 @@ module Oddb2xml
143
145
  rescue Interrupt
144
146
  files.values.each do |file|
145
147
  if File.exist? file
146
- File.unlink file
148
+ File.unlink(file) # we don't save it as it might be only partly downloaded
147
149
  end
148
150
  end
149
151
  raise Interrupt
@@ -36,13 +36,11 @@ module Oddb2xml
36
36
  end
37
37
  if File.exists? @compress_file
38
38
  @contents.each do |file|
39
- File.unlink file
39
+ Oddb2xml.download_finished(file)
40
40
  end
41
41
  end
42
42
  rescue Errno::ENOENT, StandardError
43
- if File.exists? @compress_file
44
- File.unlink @compress_file
45
- end
43
+ Oddb2xml.download_finished(@compress_file)
46
44
  return false
47
45
  end
48
46
  return true
@@ -9,18 +9,21 @@ module Oddb2xml
9
9
  private
10
10
  def download_as(file, option='r')
11
11
  data = nil
12
- begin
13
- response = @agent.get(@url)
14
- response.save_as(file)
15
- response = nil # win
12
+ if Oddb2xml.skip_download(file)
16
13
  io = File.open(file, option)
17
14
  data = io.read
18
- rescue Timeout::Error, Errno::ETIMEDOUT
19
- retrievable? ? retry : raise
20
- ensure
21
- io.close if io and !io.closed? # win
22
- if File.exists?(file)
23
- File.unlink(file)
15
+ else
16
+ begin
17
+ response = @agent.get(@url)
18
+ response.save_as(file)
19
+ response = nil # win
20
+ io = File.open(file, option)
21
+ data = io.read
22
+ rescue Timeout::Error, Errno::ETIMEDOUT
23
+ retrievable? ? retry : raise
24
+ ensure
25
+ io.close if io and !io.closed? # win
26
+ Oddb2xml.download_finished(file)
24
27
  end
25
28
  end
26
29
  return data
@@ -153,17 +156,17 @@ module Oddb2xml
153
156
  if @options[:debug]
154
157
  FileUtils.copy(File.expand_path("../../../spec/data/#{file}", __FILE__), '.')
155
158
  else
156
- response = @agent.get(@url)
157
- response.save_as(file)
158
- response = nil # win
159
+ unless Oddb2xml.skip_download(file)
160
+ response = @agent.get(@url)
161
+ response.save_as(file)
162
+ response = nil # win
163
+ end
159
164
  end
160
- return read_xml_form_zip(/^Preparation/iu, file)
165
+ read_xml_form_zip(/^Preparation/iu, file)
161
166
  rescue Timeout::Error, Errno::ETIMEDOUT
162
167
  retrievable? ? retry : raise
163
168
  ensure
164
- if File.exists?(file)
165
- File.unlink(file)
166
- end
169
+ Oddb2xml.download_finished(file)
167
170
  end
168
171
  end
169
172
  end
@@ -189,6 +192,7 @@ module Oddb2xml
189
192
  if @options[:debug]
190
193
  return File.read(File.expand_path("../../../spec/data/swissindex_#{@type}_#{@lang}.xml", __FILE__))
191
194
  end
195
+ file2save = File.expand_path("../../../data/download/swissindex_#{@type}_#{@lang}.xml", __FILE__)
192
196
  soap = <<XML
193
197
  <?xml version="1.0" encoding="utf-8"?>
194
198
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
@@ -201,6 +205,7 @@ XML
201
205
  if response.success?
202
206
  if xml = response.to_xml
203
207
  response = nil # win
208
+ File.open(file2save, 'w+') { |file| file.puts xml }
204
209
  return xml
205
210
  else
206
211
  # received broken data or internal error
@@ -239,9 +244,11 @@ XML
239
244
  page = @agent.get(@url)
240
245
  if link_node = page.search(@xpath).first
241
246
  link = Mechanize::Page::Link.new(link_node, @agent, page)
242
- response = link.click
243
- response.save_as(file)
244
- response = nil # win
247
+ unless Oddb2xml.skip_download(file)
248
+ response = link.click
249
+ response.save_as(file)
250
+ response = nil # win
251
+ end
245
252
  end
246
253
  io = File.open(file, 'rb')
247
254
  return io.read
@@ -249,9 +256,7 @@ XML
249
256
  retrievable? ? retry : raise
250
257
  ensure
251
258
  io.close if io and !io.closed?
252
- if File.exists?(file)
253
- File.unlink(file)
254
- end
259
+ Oddb2xml.download_finished(file)
255
260
  end
256
261
  end
257
262
  end
@@ -264,37 +269,29 @@ XML
264
269
  def download
265
270
  file = "swissmedic_info.zip"
266
271
  begin
267
- response = nil
268
- if home = @agent.get(@url)
269
- form = home.form_with(:id => 'Form1')
270
- bttn = form.button_with(:name => 'ctl00$MainContent$btnOK')
271
- if page = form.submit(bttn)
272
- form = page.form_with(:id => 'Form1')
273
- bttn = form.button_with(:name => 'ctl00$MainContent$BtnYes')
274
- response = form.submit(bttn)
272
+ unless Oddb2xml.skip_download(file)
273
+ response = nil
274
+ if home = @agent.get(@url)
275
+ form = home.form_with(:id => 'Form1')
276
+ bttn = form.button_with(:name => 'ctl00$MainContent$btnOK')
277
+ if page = form.submit(bttn)
278
+ form = page.form_with(:id => 'Form1')
279
+ bttn = form.button_with(:name => 'ctl00$MainContent$BtnYes')
280
+ response = form.submit(bttn)
281
+ end
282
+ end
283
+ if response
284
+ response.save_as(file)
285
+ response = nil # win
275
286
  end
276
287
  end
277
- if response
278
- response.save_as(file)
279
- response = nil # win
280
- end
281
- return read_xml_form_zip(/^AipsDownload_/iu, file)
288
+ read_xml_form_zip(/^AipsDownload_/iu, file)
282
289
  rescue Timeout::Error, Errno::ETIMEDOUT
283
290
  retrievable? ? retry : raise
284
291
  rescue NoMethodError
285
292
  # pass
286
293
  ensure
287
- # win
288
- deleted = false
289
- if File.exists?(file)
290
- until deleted
291
- begin
292
- File.unlink(file)
293
- deleted = true
294
- rescue Errno::EACCES # Permission Denied on Windows
295
- end
296
- end
297
- end
294
+ Oddb2xml.download_finished(file)
298
295
  end
299
296
  end
300
297
  end
@@ -240,6 +240,7 @@ module Oddb2xml
240
240
  no8 = sprintf('%05d',row[i_5].to_i) + sprintf('%03d',row[i_3].to_i)
241
241
  prodno = sprintf('%05d',row[i_5].to_i) + row[p_1_2].to_i.to_s
242
242
  unless no8.empty?
243
+ next if no8.to_i == 0
243
244
  ean_base12 = "7680#{no8}"
244
245
  data[no8.intern] = {
245
246
  :ean => (ean_base12.ljust(12, '0') + calc_checksum(ean_base12)),
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.6.2"
2
+ VERSION = "1.6.3"
3
3
  end
@@ -2,7 +2,82 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
+ module Kernel
6
+ def capture(stream)
7
+ begin
8
+ stream = stream.to_s
9
+ eval "$#{stream} = StringIO.new"
10
+ yield
11
+ result = eval("$#{stream}").string
12
+ ensure
13
+ eval "$#{stream} = #{stream.upcase}"
14
+ end
15
+ result
16
+ end
17
+ end
18
+
5
19
  describe Oddb2xml::Builder do
6
- it 'pending'
20
+ include ServerMockHelper
21
+ before(:all) do
22
+ files = (Dir.glob('oddb_*.tar.gz')+ Dir.glob('oddb_*.zip')+ Dir.glob('oddb_*.xml'))# +Dir.glob('data/download/*'))
23
+ files.each{ |file| FileUtils.rm(file) }
24
+ end
25
+
26
+ before(:each) do
27
+ setup_server_mocks
28
+ setup_swiss_index_server_mock(types = ['NonPharma', 'Pharma'])
29
+ end
30
+ context 'should handle BAG-articles with and without pharmacode' do
31
+ subject do
32
+ dat = File.read(File.expand_path('../data/Preparation.xml', __FILE__))
33
+ @items = Oddb2xml::BagXmlExtractor.new(dat).to_hash
34
+ end
35
+ it {
36
+ saved = @items.clone
37
+ @items = subject.to_hash
38
+ expect(@items.size).to eq(2)
39
+ expect(saved).to eq(@items)
40
+ }
41
+ end if false
42
+
43
+ context 'when no option is given' do
44
+ let(:cli) do
45
+ opts = {}
46
+ Oddb2xml::Cli.new(opts)
47
+ end
48
+ it 'should generate a valid oddb_product.xml' do
49
+ res = capture(:stdout){ cli.run }
50
+ res.should match(/products/)
51
+ article_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_article.xml'))
52
+ File.exists?(article_filename).should be_true
53
+ article_xml = IO.read(article_filename)
54
+ product_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_product.xml'))
55
+ File.exists?(product_filename).should be_true
56
+ product_xml = IO.read(product_filename)
57
+ article_xml.should match(/3TC/)
58
+ article_xml.should match(/<PHAR>1699947</)
59
+ article_xml.should match(/<SMNO>53662013</)
60
+ article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
61
+ article_xml.should match(/<COMPNO>7601001392175</)
62
+ article_xml.should match(/<BC>7680536620137</)
63
+ article_xml.should match(/<VDAT>01.10.2011</)
64
+ article_xml.should match(/<PTYP>PEXF</)
65
+ article_xml.should match(/<PRICE>164.55</)
66
+ article_xml.should match(/<PTYP>PPUB</)
67
+ article_xml.should match(/<PRICE>205.3</)
68
+
69
+ article_xml.should match(/Levetiracetam DESITIN/i) #
70
+ article_xml.should match(/7680536620137/) # Pharmacode
71
+ article_xml.should match(/<PRICE>13.49</)
72
+ article_xml.should match(/<PRICE>27.8</)
73
+
74
+ product_xml.should match(/3TC/)
75
+ product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
76
+ article_xml.scan(/<ART DT=/).size.should eq(2) # we should find two articles
77
+ article_xml.should match(/<PHAR>5819012</)
78
+ article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
79
+ article_xml.should match(/<COMPNO>7601001320451</)
80
+ end
81
+ end
7
82
  end
8
83
 
@@ -46,6 +46,10 @@ end
46
46
 
47
47
  describe Oddb2xml::Cli do
48
48
  include ServerMockHelper
49
+ before(:all) do
50
+ files = (Dir.glob('oddb_*.tar.gz')+ Dir.glob('oddb_*.zip')+ Dir.glob('oddb_*.xml'))# +Dir.glob('data/download/*'))
51
+ files.each{ |file| FileUtils.rm(file) }
52
+ end
49
53
  before(:each) do
50
54
  setup_server_mocks
51
55
  end
@@ -72,7 +76,7 @@ describe Oddb2xml::Cli do
72
76
  it 'should not create any xml file' do
73
77
  capture(:stdout) { cli.run }.should match(/Pharma/)
74
78
  Dir.glob('oddb_*.xml').each do |file|
75
- File.exists?(file).should be_nil
79
+ File.exists?(file).should be_false
76
80
  end
77
81
  end
78
82
  after(:each) do
@@ -104,7 +108,7 @@ describe Oddb2xml::Cli do
104
108
  it 'should not create any xml file' do
105
109
  capture(:stdout) { cli.run }.should match(/Pharma/)
106
110
  Dir.glob('oddb_*.xml').each do |file|
107
- File.exists?(file).should be_nil
111
+ File.exists?(file).should be_false
108
112
  end
109
113
  end
110
114
  after(:each) do
@@ -1,55 +1,41 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
- <soap:Envelope
3
- xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
4
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
- xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
6
3
  <soap:Body>
7
- <PHARMA
4
+ <PHARMA xmlns="http://swissindex.e-mediat.net/SwissindexPharma_out_V101" CREATION_DATETIME="2013-12-10T10:09:26.8198427+01:00">
5
+ <!-- spec/data/swissindex_pharma.xml. Values for spec/builder_spec.rb -->
8
6
  CREATION_DATETIME="2012-10-18T06:31:19.4687619+02:00"
9
7
  xmlns="http://example.com/test">
10
- <ITEM DT="2012-10-18T00:00:00">
11
- <GTIN>0000000000000</GTIN>
12
- <PHAR>00000</PHAR>
8
+ <ITEM DT="2013-06-22T00:00:00">
9
+ <GTIN>7680536620137</GTIN>
10
+ <PHAR>1699947</PHAR>
13
11
  <STATUS>A</STATUS>
14
- <STDATE>2002-05-23T00:00:00</STDATE>
12
+ <STDATE>1996-03-20T00:00:00</STDATE>
15
13
  <LANG>DE</LANG>
16
- <DSCR>Foo 1000 mg</DSCR>
17
- <ADDSCR>Amp</ADDSCR>
18
- <ATC>A00AA00</ATC>
14
+ <DSCR>3TC Filmtabl 150 mg</DSCR>
15
+ <ADDSCR>60 Stk</ADDSCR>
16
+ <ATC>J05AF05</ATC>
19
17
  <COMP>
20
- <NAME>EXAMPLE.COM AG</NAME>
21
- <GLN>0000000000000</GLN>
18
+ <NAME>ViiV Healthcare GmbH</NAME>
19
+ <GLN>7601001392175</GLN>
22
20
  </COMP>
23
21
  </ITEM>
24
- <ITEM DT="2012-10-18T00:00:00">
25
- <GTIN>0000000000001</GTIN>
26
- <PHAR>00001</PHAR>
22
+ <ITEM DT="2013-12-06T00:00:00">
23
+ <GTIN>7680620690084</GTIN>
24
+ <PHAR>5819012</PHAR>
27
25
  <STATUS>A</STATUS>
28
- <STDATE>2002-05-23T00:00:00</STDATE>
26
+ <STDATE>2013-10-26T00:00:00</STDATE>
29
27
  <LANG>DE</LANG>
30
- <DSCR>Bar 10 Stk</DSCR>
31
- <ADDSCR>10 Stk</ADDSCR>
32
- <ATC>A02AA02</ATC>
28
+ <DSCR>LEVETIRACETAM DESITIN Filmtabl 250 mg</DSCR>
29
+ <ADDSCR>30 Stk</ADDSCR>
30
+ <ATC>N03AX14</ATC>
33
31
  <COMP>
34
- <NAME>EXAMPLE.ORG AG</NAME>
35
- </COMP>
36
- </ITEM>
37
- <ITEM DT="2012-10-18T00:00:00">
38
- <GTIN>0000000000002</GTIN>
39
- <PHAR>00002</PHAR>
40
- <STATUS>A</STATUS>
41
- <STDATE>2002-05-23T00:00:00</STDATE>
42
- <LANG>DE</LANG>
43
- <DSCR>Baz 10 Tablet</DSCR>
44
- <ADDSCR>5 Stk</ADDSCR>
45
- <ATC>A03AA03</ATC>
46
- <COMP>
47
- <NAME>EXAMPLE.AC AG</NAME>
32
+ <NAME>Desitin Pharma GmbH</NAME>
33
+ <GLN>7601001320451</GLN>
48
34
  </COMP>
49
35
  </ITEM>
50
36
  <RESULT>
51
37
  <OK_ERROR>OK</OK_ERROR>
52
- <NBR_RECORD>3</NBR_RECORD>
38
+ <NBR_RECORD>2</NBR_RECORD>
53
39
  </RESULT>
54
40
  </PHARMA>
55
41
  </soap:Body>
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require "#{Dir.pwd}/lib/oddb2xml/downloader"
4
5
 
5
6
  describe Oddb2xml::Extractor do
6
7
  it "pending"
@@ -41,27 +42,49 @@ describe Oddb2xml::SwissIndexExtractor do
41
42
  it "pending"
42
43
  end
43
44
 
44
- describe Oddb2xml::SwissmedicExtractor do
45
+ describe Oddb2xml::BMUpdateExtractor do
45
46
  it "pending"
46
47
  end
47
48
 
48
- describe Oddb2xml::MigelExtractor do
49
+ describe Oddb2xml::LppvExtractor do
49
50
  it "pending"
50
51
  end
51
52
 
52
- describe Oddb2xml::SwissmedicInfoExtractor do
53
+ describe Oddb2xml::SwissIndexExtractor do
53
54
  it "pending"
54
55
  end
55
56
 
56
- describe Oddb2xml::EphaExtractor do
57
+ describe Oddb2xml::MigelExtractor do
57
58
  it "pending"
58
59
  end
59
60
 
60
- describe Oddb2xml::MedregbmExtractor do
61
- it "pending"
61
+ describe Oddb2xml::SwissmedicInfoExtractor do
62
+ context 'when transfer.dat is empty' do
63
+ subject { Oddb2xml::SwissmedicInfoExtractor.new("") }
64
+ it { expect(subject.to_hash).to be_empty }
65
+ end
66
+ context 'can parse swissmedic_packages.xls' do
67
+ it {
68
+ filename = File.join(File.dirname(__FILE__), 'data/swissmedic_packages.xls')
69
+ bin = IO.read(filename)
70
+ @packs = Oddb2xml::SwissmedicExtractor.new(bin, :package).to_hash
71
+ expect(@packs.size).to eq(14)
72
+ }
73
+ end
62
74
  end
63
75
 
64
- describe Oddb2xml::ZurroseExtractor do
76
+ describe Oddb2xml::EphaExtractor do
77
+ context 'can parse epha_interactions.csv' do
78
+ it {
79
+ filename = File.join(File.dirname(__FILE__), 'data/epha_interactions.csv')
80
+ string = IO.read(filename)
81
+ @actions = Oddb2xml::EphaExtractor.new(string).to_arry
82
+ expect(@actions.size).to eq(2)
83
+ }
84
+ end
85
+ end
86
+
87
+ describe Oddb2xml::MedregbmExtractor do
65
88
  it "pending"
66
89
  end
67
90
 
@@ -42,8 +42,8 @@ module ServerMockHelper
42
42
  :headers => {'Content-Type' => 'application/zip; charset=utf-8'},
43
43
  :body => stub_response)
44
44
  end
45
- def setup_swiss_index_server_mock
46
- ['Pharma', 'NonPharma'].each do |type|
45
+ def setup_swiss_index_server_mock(types = ['Pharma', 'NonPharma'])
46
+ types.each do |type|
47
47
  # wsdl
48
48
  stub_wsdl_url = "https://index.ws.e-mediat.net/Swissindex/#{type}/ws_#{type}_V101.asmx?WSDL"
49
49
  stub_response = File.read(File.expand_path("../data/wsdl_#{type.downcase}.xml", __FILE__))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-09 00:00:00.000000000 Z
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip