oddb2xml 1.6.8 → 1.6.9
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.
- data/History.txt +5 -0
- data/Manifest.txt +3 -3
- data/Rakefile +1 -1
- data/lib/oddb2xml/downloader.rb +1 -0
- data/lib/oddb2xml/extractor.rb +9 -13
- data/lib/oddb2xml/version.rb +1 -1
- data/spec/data/swissmedic_orphans.xls +0 -0
- data/spec/data/{swissmedic_orphan.xls → swissmedic_packages.xls} +0 -0
- data/spec/extractor_spec.rb +7 -6
- data/spec/spec_helper.rb +14 -11
- metadata +8 -8
- /data/spec/data/{swissmedic_fridge.xlsx → swissmedic_fridges.xlsx} +0 -0
- /data/spec/data/{swissmedic_package.xlsx → swissmedic_packages.xlsx} +0 -0
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -45,17 +45,17 @@ spec/data/oddb_substance.xml
|
|
45
45
|
spec/data/swissindex.xml
|
46
46
|
spec/data/swissindex_nonpharma.xml
|
47
47
|
spec/data/swissindex_pharma.xml
|
48
|
-
spec/data/swissmedic_fridge.xlsx
|
49
48
|
spec/data/swissmedic_fridges.html
|
50
49
|
spec/data/swissmedic_fridges.xls
|
50
|
+
spec/data/swissmedic_fridges.xlsx
|
51
51
|
spec/data/swissmedic_info.html
|
52
52
|
spec/data/swissmedic_info.zip
|
53
53
|
spec/data/swissmedic_info_2.html
|
54
|
-
spec/data/swissmedic_orphan.xls
|
55
54
|
spec/data/swissmedic_orphans.html
|
56
55
|
spec/data/swissmedic_orphans.xls
|
57
|
-
spec/data/swissmedic_package.xlsx
|
58
56
|
spec/data/swissmedic_packages.html
|
57
|
+
spec/data/swissmedic_packages.xls
|
58
|
+
spec/data/swissmedic_packages.xlsx
|
59
59
|
spec/data/wsdl.xml
|
60
60
|
spec/data/wsdl_nonpharma.xml
|
61
61
|
spec/data/wsdl_pharma.xml
|
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ Hoe.spec 'oddb2xml' do
|
|
19
19
|
self.urls = ["https://github.com/zdavatz/oddb2xml"] # gem.homepage
|
20
20
|
|
21
21
|
# gem.add_runtime_dependency
|
22
|
-
self.extra_deps << ['rubyzip']
|
22
|
+
self.extra_deps << ['rubyzip', '~> 0.9.9']
|
23
23
|
self.extra_deps << ['archive-tar-minitar']
|
24
24
|
self.extra_deps << ['mechanize', '~> 2.5.1']
|
25
25
|
self.extra_deps << ['nokogiri']
|
data/lib/oddb2xml/downloader.rb
CHANGED
data/lib/oddb2xml/extractor.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'nokogiri'
|
4
4
|
require 'spreadsheet'
|
5
5
|
require 'stringio'
|
6
|
+
require 'rubyXL'
|
6
7
|
|
7
8
|
module Oddb2xml
|
8
9
|
module TxtExtractorMethods
|
@@ -197,6 +198,7 @@ module Oddb2xml
|
|
197
198
|
end
|
198
199
|
class SwissmedicExtractor < Extractor
|
199
200
|
def initialize(filename, type)
|
201
|
+
@filename = filename
|
200
202
|
@type = type
|
201
203
|
if type == :orphan
|
202
204
|
book = Spreadsheet.open(filename, 'rb')
|
@@ -224,6 +226,7 @@ module Oddb2xml
|
|
224
226
|
end
|
225
227
|
end
|
226
228
|
end
|
229
|
+
cleanup_file
|
227
230
|
data.uniq
|
228
231
|
end
|
229
232
|
def to_hash # Packungen.xls
|
@@ -261,24 +264,17 @@ module Oddb2xml
|
|
261
264
|
end
|
262
265
|
end
|
263
266
|
end
|
267
|
+
cleanup_file
|
264
268
|
data
|
265
269
|
end
|
266
270
|
private
|
267
|
-
def
|
271
|
+
def cleanup_file
|
268
272
|
begin
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
number = number.rjust(5, '0') if ptrn == /^\d{5}$/
|
273
|
-
if number =~ ptrn
|
274
|
-
return number
|
275
|
-
else
|
276
|
-
nil
|
277
|
-
end
|
278
|
-
rescue NoMethodError
|
279
|
-
nil
|
280
|
-
end
|
273
|
+
File.unlink(@filename) if File.exists?(@filename)
|
274
|
+
rescue Errno::EACCES # Permission Denied on Windows
|
275
|
+
end unless defined?(RSpec)
|
281
276
|
end
|
277
|
+
|
282
278
|
def calc_checksum(str)
|
283
279
|
str = str.strip
|
284
280
|
sum = 0
|
data/lib/oddb2xml/version.rb
CHANGED
Binary file
|
Binary file
|
data/spec/extractor_spec.rb
CHANGED
@@ -63,9 +63,9 @@ describe Oddb2xml::SwissmedicInfoExtractor do
|
|
63
63
|
subject { Oddb2xml::SwissmedicInfoExtractor.new("") }
|
64
64
|
it { expect(subject.to_hash).to be_empty }
|
65
65
|
end
|
66
|
-
context 'can parse
|
66
|
+
context 'can parse swissmedic_packages.xlsx' do
|
67
67
|
it {
|
68
|
-
filename = File.join(File.dirname(__FILE__), 'data/
|
68
|
+
filename = File.join(File.dirname(__FILE__), 'data/swissmedic_packages.xlsx')
|
69
69
|
@packs = Oddb2xml::SwissmedicExtractor.new(filename, :package).to_hash
|
70
70
|
expect(@packs.size).to eq(14)
|
71
71
|
first = @packs.first[1]
|
@@ -77,18 +77,19 @@ describe Oddb2xml::SwissmedicInfoExtractor do
|
|
77
77
|
expect(@packs.first[0].to_s).to eq('00274001')
|
78
78
|
}
|
79
79
|
end
|
80
|
-
context 'can parse
|
80
|
+
context 'can parse swissmedic_fridges.xlsx' do
|
81
81
|
it {
|
82
|
-
filename = File.join(File.dirname(__FILE__), 'data/
|
82
|
+
filename = File.join(File.dirname(__FILE__), 'data/swissmedic_fridges.xlsx')
|
83
83
|
@packs = Oddb2xml::SwissmedicExtractor.new(filename, :fridge).to_arry
|
84
84
|
expect(@packs.size).to eq(17)
|
85
85
|
expect(@packs[0]).to eq("58618")
|
86
86
|
expect(@packs[1]).to eq("00696")
|
87
87
|
}
|
88
88
|
end
|
89
|
-
context 'can parse
|
89
|
+
context 'can parse swissmedic_orphans.xls' do
|
90
90
|
it {
|
91
|
-
filename = File.join(File.dirname(__FILE__), 'data/
|
91
|
+
filename = File.join(File.dirname(__FILE__), 'data/swissmedic_orphans.xls')
|
92
|
+
expect(File.exists?(filename)).to eq(true), "File #{filename} must exists"
|
92
93
|
@packs = Oddb2xml::SwissmedicExtractor.new(filename, :orphan).to_arry
|
93
94
|
expect(@packs.size).to eq(72)
|
94
95
|
expect(@packs.first).to eq("62132")
|
data/spec/spec_helper.rb
CHANGED
@@ -72,26 +72,29 @@ module ServerMockHelper
|
|
72
72
|
end
|
73
73
|
def setup_swissmedic_server_mock
|
74
74
|
host = 'www.swissmedic.ch'
|
75
|
-
{
|
76
|
-
:orphans => {:html => '/
|
77
|
-
:fridges => {:html => '/
|
78
|
-
:packages => {:html => '/
|
75
|
+
{
|
76
|
+
:orphans => {:html => '/arzneimittel/00156/00221/00222/00223/00224/00227/00228/index.html?lang=de', :xls => '/download'},
|
77
|
+
:fridges => {:html => '/arzneimittel/00156/00221/00222/00235/index.html?lang=de', :xls => '/download'},
|
78
|
+
:packages => {:html => '/arzneimittel/00156/00221/00222/00230/index.html?lang=de', :xls => '/download'},
|
79
79
|
}.each_pair do |type, urls|
|
80
80
|
# html (dummy)
|
81
81
|
stub_html_url = "http://#{host}" + urls[:html]
|
82
|
-
|
82
|
+
filename = File.expand_path("../data/swissmedic_#{type.to_s}.html", __FILE__)
|
83
|
+
stub_response = File.read(filename)
|
83
84
|
stub_request(:get, stub_html_url).
|
84
|
-
|
85
|
-
'Accept' => '*/*',
|
86
|
-
'Host' => host,
|
87
|
-
}).
|
85
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Charset'=>'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Accept-Encoding'=>'gzip,deflate,identity', 'Accept-Language'=>'en-us,en;q=0.5', 'Connection'=>'keep-alive', 'Host'=> host, 'Keep-Alive'=>'300', 'User-Agent'=>'Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0'}).
|
88
86
|
to_return(
|
89
87
|
:status => 200,
|
90
88
|
:headers => {'Content-Type' => 'text/html; charset=utf-8'},
|
91
89
|
:body => stub_response)
|
92
90
|
# xls
|
93
|
-
|
94
|
-
|
91
|
+
if type == :orphans
|
92
|
+
stub_xls_url = "http://#{host}" + urls[:xls] + "/swissmedic_#{type.to_s}.xls"
|
93
|
+
stub_response = File.read(File.expand_path("../data/swissmedic_#{type.to_s}.xls", __FILE__))
|
94
|
+
else
|
95
|
+
stub_xls_url = "http://#{host}" + urls[:xls] + "/swissmedic_#{type.to_s}.xlsx"
|
96
|
+
stub_response = File.read(File.expand_path("../data/swissmedic_#{type.to_s}.xlsx", __FILE__))
|
97
|
+
end
|
95
98
|
stub_request(:get, stub_xls_url).
|
96
99
|
with(:headers => {
|
97
100
|
'Accept' => '*/*',
|
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.
|
4
|
+
version: 1.6.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,17 +16,17 @@ dependencies:
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.9.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.9.9
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: archive-tar-minitar
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -245,17 +245,17 @@ files:
|
|
245
245
|
- spec/data/swissindex.xml
|
246
246
|
- spec/data/swissindex_nonpharma.xml
|
247
247
|
- spec/data/swissindex_pharma.xml
|
248
|
-
- spec/data/swissmedic_fridge.xlsx
|
249
248
|
- spec/data/swissmedic_fridges.html
|
250
249
|
- spec/data/swissmedic_fridges.xls
|
250
|
+
- spec/data/swissmedic_fridges.xlsx
|
251
251
|
- spec/data/swissmedic_info.html
|
252
252
|
- spec/data/swissmedic_info.zip
|
253
253
|
- spec/data/swissmedic_info_2.html
|
254
|
-
- spec/data/swissmedic_orphan.xls
|
255
254
|
- spec/data/swissmedic_orphans.html
|
256
255
|
- spec/data/swissmedic_orphans.xls
|
257
|
-
- spec/data/swissmedic_package.xlsx
|
258
256
|
- spec/data/swissmedic_packages.html
|
257
|
+
- spec/data/swissmedic_packages.xls
|
258
|
+
- spec/data/swissmedic_packages.xlsx
|
259
259
|
- spec/data/wsdl.xml
|
260
260
|
- spec/data/wsdl_nonpharma.xml
|
261
261
|
- spec/data/wsdl_pharma.xml
|
File without changes
|
File without changes
|