swissmedic-diff 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +20 -2
- data/History.txt +6 -0
- data/Manifest.txt +3 -1
- data/lib/compatibility.rb +59 -0
- data/lib/swissmedic-diff.rb +11 -21
- data/lib/version.rb +1 -1
- data/swissmedic-diff.gemspec +1 -1
- data/test/data/Packungen_2013_small.xls +0 -0
- data/test/data/Packungen_2014_small.xlsx +0 -0
- data/test/test_swissmedic-diff.rb +54 -6
- metadata +9 -13
- data/test/data/Packungen-2014.xlsx +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2M2ZjQwMDk0YmZmYmNmNzZjNDZlMWI2ZDc5OTU3MGVlZTJmOWQxZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjI1NTljZGZhMTA2N2I0YmI3MDZlZWJiYWNjNWY5NTNjOGE1NjAxZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NWI3ZWYwYjg2NjE1ZDc3Yzk3NDBjMDY4N2RhZTAxMWFjMzJkYWMzNDJjZGU5
|
10
|
+
MmM5ODMwYTBlYTgzZDk3M2MxYTBlMjBkYzQzYjRkOWE4NmE1Y2U2NTk3MDQ0
|
11
|
+
YzMwN2I0NmQ3MjNkMjYxNjc2NjJiNTIxODAzMDc4M2I2MDIxYTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDViOTFhOGFkY2JhYTgxOGE3ZjM0MmNmZmE2Y2I5MzMyZDFkMzI4MTZhM2I3
|
14
|
+
OTU1NzQ5ZTY4MTczMDU3ZjczNTY4ZTdkYWEwZjRmMDlhYmJiNGRiZmE2ZGM4
|
15
|
+
MjViYTU0MWU3ODgyOTY1MmIzOTRlMmEwOTBlZmM5ZmEzZWUzMzk=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swissmedic-diff (0.1.
|
4
|
+
swissmedic-diff (0.1.6)
|
5
5
|
nokogiri
|
6
6
|
rubyXL
|
7
|
-
rubyzip
|
7
|
+
rubyzip (= 0.9.9)
|
8
8
|
spreadsheet
|
9
9
|
|
10
10
|
GEM
|
@@ -12,9 +12,18 @@ GEM
|
|
12
12
|
specs:
|
13
13
|
ansi (1.4.3)
|
14
14
|
builder (3.2.2)
|
15
|
+
coderay (1.1.0)
|
16
|
+
columnize (0.3.6)
|
17
|
+
debugger (1.6.5)
|
18
|
+
columnize (>= 0.3.1)
|
19
|
+
debugger-linecache (~> 1.2.0)
|
20
|
+
debugger-ruby_core_source (~> 1.3.1)
|
21
|
+
debugger-linecache (1.2.0)
|
22
|
+
debugger-ruby_core_source (1.3.1)
|
15
23
|
hashie (2.0.5)
|
16
24
|
hoe (3.7.4)
|
17
25
|
rake (>= 0.8, < 11.0)
|
26
|
+
method_source (0.8.2)
|
18
27
|
mini_portile (0.5.2)
|
19
28
|
minitest (5.2.1)
|
20
29
|
minitest-reporters (1.0.0)
|
@@ -27,10 +36,18 @@ GEM
|
|
27
36
|
powerbar (1.0.11)
|
28
37
|
ansi (~> 1.4.0)
|
29
38
|
hashie (>= 1.1.0)
|
39
|
+
pry (0.9.12.4)
|
40
|
+
coderay (~> 1.0)
|
41
|
+
method_source (~> 0.8)
|
42
|
+
slop (~> 3.4)
|
43
|
+
pry-debugger (0.2.2)
|
44
|
+
debugger (~> 1.3)
|
45
|
+
pry (~> 0.9.10)
|
30
46
|
rake (10.1.1)
|
31
47
|
ruby-ole (1.2.11.7)
|
32
48
|
rubyXL (1.2.10)
|
33
49
|
rubyzip (0.9.9)
|
50
|
+
slop (3.4.7)
|
34
51
|
spreadsheet (0.9.6)
|
35
52
|
ruby-ole (>= 1.0)
|
36
53
|
|
@@ -41,5 +58,6 @@ DEPENDENCIES
|
|
41
58
|
hoe
|
42
59
|
minitest
|
43
60
|
minitest-reporters
|
61
|
+
pry-debugger
|
44
62
|
rake
|
45
63
|
swissmedic-diff!
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -8,14 +8,16 @@ Manifest.txt
|
|
8
8
|
README.txt
|
9
9
|
Rakefile
|
10
10
|
bin/swissmedic-diff
|
11
|
+
lib/compatibility.rb
|
11
12
|
lib/swissmedic-diff.rb
|
12
13
|
lib/version.rb
|
13
14
|
setup.rb
|
14
15
|
swissmedic-diff.gemspec
|
15
16
|
test/data/Packungen-2013.10.14.xls
|
16
|
-
test/data/Packungen-2014.xlsx
|
17
17
|
test/data/Packungen.older.xls
|
18
18
|
test/data/Packungen.xls
|
19
|
+
test/data/Packungen_2013_small.xls
|
20
|
+
test/data/Packungen_2014_small.xlsx
|
19
21
|
test/data/Packungen_error_column.xls
|
20
22
|
test/data/Packungen_error_missing1.xls
|
21
23
|
test/data/Packungen_error_missing2.xls
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
require 'spreadsheet'
|
4
|
+
require 'rubyXL'
|
5
|
+
|
6
|
+
module Spreadsheet
|
7
|
+
class << self
|
8
|
+
def open io_or_path, mode="rb+"
|
9
|
+
if File.extname(io_or_path).downcase == '.xlsx'
|
10
|
+
RubyXL::Parser.parse(io_or_path)
|
11
|
+
else
|
12
|
+
if io_or_path.respond_to? :seek
|
13
|
+
Excel::Workbook.open(io_or_path)
|
14
|
+
elsif block_given?
|
15
|
+
File.open(io_or_path, mode) do |fh|
|
16
|
+
yield open(fh)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
open File.open(io_or_path, mode)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def Spreadsheet.date_cell(row, idx)
|
25
|
+
if row.kind_of?(Spreadsheet::Excel::Row)
|
26
|
+
row.at(idx) && row.date(idx)
|
27
|
+
else
|
28
|
+
data = row[idx]
|
29
|
+
return Date.new(1899,12,30)+data.value.to_i if data.is_a?(RubyXL::Cell)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module RubyXL
|
35
|
+
class Worksheet < PrivateClass
|
36
|
+
def row(row_index)
|
37
|
+
x = @sheet_data[row_index]
|
38
|
+
def x.date(column_index)
|
39
|
+
data = self[column_index]
|
40
|
+
return Date.new(1899,12,30)+data.value.to_i if data.is_a?(RubyXL::Cell)
|
41
|
+
end unless defined?(x.date)
|
42
|
+
x
|
43
|
+
end
|
44
|
+
end
|
45
|
+
class Workbook
|
46
|
+
def worksheet(idx)
|
47
|
+
self[idx]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
class Cell
|
51
|
+
def to_i
|
52
|
+
self.value.to_i
|
53
|
+
end
|
54
|
+
def to_s
|
55
|
+
self.value.to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/swissmedic-diff.rb
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
require 'ostruct'
|
6
6
|
require 'spreadsheet'
|
7
7
|
require 'rubyXL'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
# add some monkey patches for Spreadsheet and rubyXL
|
11
|
+
require File.join(File.dirname(__FILE__), 'compatibility.rb')
|
8
12
|
|
9
13
|
#= diff command (compare two xls fles) for swissmedic xls file.
|
10
14
|
#
|
@@ -96,11 +100,7 @@ class SwissmedicDiff
|
|
96
100
|
@diff.changes = changes = {}
|
97
101
|
@diff.newest_rows = newest_rows
|
98
102
|
Spreadsheet.client_encoding = 'UTF-8'
|
99
|
-
|
100
|
-
tbook = RubyXL::Parser.parse(File.expand_path(target))
|
101
|
-
else
|
102
|
-
tbook = Spreadsheet.open(target)
|
103
|
-
end
|
103
|
+
tbook = Spreadsheet.open(target)
|
104
104
|
sheet = tbook.worksheet(0)
|
105
105
|
if new_column = cell(sheet.row(2), COLUMNS.size)
|
106
106
|
raise "New column #{COLUMNS.size} (#{new_column})"
|
@@ -181,11 +181,7 @@ class SwissmedicDiff
|
|
181
181
|
[known_regs, known_seqs, known_pacs, newest_rows]
|
182
182
|
end
|
183
183
|
def _known_data(latest, known_regs, known_seqs, known_pacs, newest_rows)
|
184
|
-
|
185
|
-
lbook = RubyXL::Parser.parse(File.expand_path(latest)).worksheets[0]
|
186
|
-
else
|
187
|
-
lbook = Spreadsheet.open(latest)
|
188
|
-
end
|
184
|
+
lbook = Spreadsheet.open(latest)
|
189
185
|
idx, prr, prp = nil
|
190
186
|
multiples = {}
|
191
187
|
each_valid_row(lbook) { |row|
|
@@ -222,6 +218,8 @@ class SwissmedicDiff
|
|
222
218
|
COLUMNS.each_with_index { |key, idx|
|
223
219
|
if(!ignore.include?(key) \
|
224
220
|
&& _comparable(key, row, idx) != _comparable(key, other, idx))
|
221
|
+
# binding.pry if key == :expiry_date
|
222
|
+
|
225
223
|
flags.push key
|
226
224
|
end
|
227
225
|
}
|
@@ -273,7 +271,7 @@ class SwissmedicDiff
|
|
273
271
|
if cell = row[idx]
|
274
272
|
case key
|
275
273
|
when :registration_date, :expiry_date
|
276
|
-
row
|
274
|
+
Spreadsheet.date_cell(row, idx)
|
277
275
|
when :seqnr
|
278
276
|
sprintf "%02i", cell.to_i
|
279
277
|
else
|
@@ -297,11 +295,7 @@ class SwissmedicDiff
|
|
297
295
|
#return ::
|
298
296
|
def each_valid_row(spreadsheet)
|
299
297
|
skipRows = rows_to_skip(spreadsheet)
|
300
|
-
|
301
|
-
worksheet = spreadsheet
|
302
|
-
else
|
303
|
-
worksheet = spreadsheet.worksheet(0)
|
304
|
-
end
|
298
|
+
worksheet = spreadsheet.worksheet(0)
|
305
299
|
row_nr = 0
|
306
300
|
worksheet.each() {
|
307
301
|
|row|
|
@@ -323,11 +317,7 @@ class SwissmedicDiff
|
|
323
317
|
# Packungen.xls of swissmedic before October 2013 had 3 leading rows
|
324
318
|
# Packungen.xls of swissmedic after October 2013 have 4 leading rows
|
325
319
|
j = 0
|
326
|
-
|
327
|
-
j += 1 while spreadsheet[j][0] and spreadsheet[j][0].value.to_i == 0
|
328
|
-
else
|
329
|
-
j += 1 while spreadsheet.worksheet(0).row(j)[0].to_i == 0
|
330
|
-
end
|
320
|
+
j += 1 while spreadsheet.worksheet(0).row(j)[0].to_i == 0
|
331
321
|
j
|
332
322
|
end
|
333
323
|
|
data/lib/version.rb
CHANGED
data/swissmedic-diff.gemspec
CHANGED
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
|
|
17
17
|
s.executables << 'swissmedic-diff'
|
18
18
|
s.add_dependency('rubyXL')
|
19
19
|
s.add_dependency('nokogiri')
|
20
|
-
s.add_dependency('rubyzip')
|
20
|
+
s.add_dependency('rubyzip', '0.9.9')
|
21
21
|
s.add_dependency('spreadsheet')
|
22
22
|
s.add_development_dependency "hoe"
|
23
23
|
s.add_development_dependency "minitest"
|
Binary file
|
Binary file
|
@@ -26,19 +26,67 @@ module ODDB
|
|
26
26
|
File.dirname(__FILE__)
|
27
27
|
@workbook = Spreadsheet.open(@data)
|
28
28
|
end
|
29
|
-
|
30
|
-
# Instead it might just tell you how to test with real data
|
29
|
+
|
31
30
|
def test_diff_xls_and_xlsx
|
32
31
|
@diff = SwissmedicDiff.new
|
33
|
-
last_month = File.expand_path 'data/
|
34
|
-
this_month = File.expand_path 'data/
|
32
|
+
last_month = File.expand_path 'data/Packungen_2013_small.xls', File.dirname(__FILE__)
|
33
|
+
this_month = File.expand_path 'data/Packungen_2014_small.xlsx', File.dirname(__FILE__)
|
35
34
|
result = @diff.diff last_month, this_month, [:atc_class, :sequence_date]
|
36
35
|
assert(result.changes.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
|
37
|
-
|
38
|
-
|
36
|
+
# puts "Got #{result.news.size} news, #{result.changes.size} changes, #{result.updates.size} updates."
|
37
|
+
assert_equal(8, result.news.size)
|
38
|
+
assert_equal(3, result.changes.size)
|
39
|
+
assert_equal(1, result.updates.size)
|
40
|
+
assert(result.news.first.index('00280'), "Should find 00280 in news")
|
41
|
+
assert(result.news.flatten.index('65034'), "Should find 65034 in news")
|
42
|
+
assert(result.news.flatten.index('00277') == nil, "Should not find 00277 in news")
|
39
43
|
assert(result.news.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
|
40
44
|
end
|
45
|
+
|
46
|
+
def test_date_xls
|
47
|
+
tbook = Spreadsheet.open(File.expand_path('data/Packungen.xls', File.dirname(__FILE__)))
|
48
|
+
sheet = tbook.worksheet(0)
|
49
|
+
assert_equal(nil, sheet.row(0)[8]) # sequence_date
|
50
|
+
assert_equal(2010, sheet.row(4).date(8).year)
|
51
|
+
assert_equal(26, sheet.row(4).date(8).day)
|
52
|
+
# assert_equal(26, Spreadsheet.date_cell(sheet.row(4), 8))
|
53
|
+
assert_equal(26, Spreadsheet.date_cell(sheet.row(4), 8).day)
|
54
|
+
assert_equal(2010, Spreadsheet.date_cell(sheet.row(4), 8).year)
|
55
|
+
end
|
41
56
|
|
57
|
+
def test_date_xlsx
|
58
|
+
tbook = Spreadsheet.open(File.expand_path('data/Packungen_2014_small.xlsx', File.dirname(__FILE__)))
|
59
|
+
sheet = tbook.worksheet(0)
|
60
|
+
# sheet = RubyXL::Parser.parse(File.expand_path(File.expand_path 'data/Packungen_2014_small.xlsx', File.dirname(__FILE__)))[0]
|
61
|
+
assert_equal(nil, sheet.row(0)[8]) # sequence_date
|
62
|
+
assert_equal(2010, sheet.row(4).date(8).year)
|
63
|
+
assert_equal(26, sheet.row(4).date(8).day)
|
64
|
+
assert_equal(26, Spreadsheet.date_cell(sheet.row(4), 8).day)
|
65
|
+
assert_equal(2010, Spreadsheet.date_cell(sheet.row(4), 8).year)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_diff_xlsx_and_xls
|
69
|
+
@diff = SwissmedicDiff.new
|
70
|
+
last_month = File.expand_path 'data/Packungen_2014_small.xlsx', File.dirname(__FILE__)
|
71
|
+
this_month = File.expand_path 'data/Packungen.xls', File.dirname(__FILE__)
|
72
|
+
result = @diff.diff last_month, this_month, [:atc_class, :sequence_date]
|
73
|
+
assert_equal(7, result.news.size)
|
74
|
+
assert_equal(2, result.updates.size)
|
75
|
+
assert_equal(10, result.changes.size)
|
76
|
+
assert(result.changes.flatten.index('00275'), "Should find 00275 in changes")
|
77
|
+
assert(result.changes.flatten.index('00277'), "Should find 00277 in changes")
|
78
|
+
assert(result.news.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
|
79
|
+
end
|
80
|
+
def test_diff_xlsx_and_xlsx
|
81
|
+
@diff = SwissmedicDiff.new
|
82
|
+
last_month = File.expand_path 'data/Packungen_2014_small.xlsx', File.dirname(__FILE__)
|
83
|
+
this_month = File.expand_path 'data/Packungen_2014_small.xlsx', File.dirname(__FILE__)
|
84
|
+
result = @diff.diff last_month, this_month, [:atc_class, :sequence_date]
|
85
|
+
assert_equal({}, result.changes)
|
86
|
+
assert_equal([], result.news)
|
87
|
+
assert_equal([], result.updates)
|
88
|
+
end
|
89
|
+
|
42
90
|
# This is not a unit test as it takes way too long (> 1 minute)
|
43
91
|
# Instead it might just tell you how to test with real data
|
44
92
|
def test_real_diff
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swissmedic-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rdoc
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: hoe
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -65,6 +60,7 @@ extra_rdoc_files:
|
|
65
60
|
- Manifest.txt
|
66
61
|
- README.txt
|
67
62
|
files:
|
63
|
+
- .gemtest
|
68
64
|
- .gitignore
|
69
65
|
- .travis.yml
|
70
66
|
- Gemfile
|
@@ -75,21 +71,23 @@ files:
|
|
75
71
|
- README.txt
|
76
72
|
- Rakefile
|
77
73
|
- bin/swissmedic-diff
|
74
|
+
- lib/compatibility.rb
|
78
75
|
- lib/swissmedic-diff.rb
|
79
76
|
- lib/version.rb
|
80
77
|
- setup.rb
|
81
78
|
- swissmedic-diff.gemspec
|
82
79
|
- test/data/Packungen-2013.10.14.xls
|
83
|
-
- test/data/Packungen-2014.xlsx
|
84
80
|
- test/data/Packungen.older.xls
|
85
81
|
- test/data/Packungen.xls
|
82
|
+
- test/data/Packungen_2013_small.xls
|
83
|
+
- test/data/Packungen_2014_small.xlsx
|
86
84
|
- test/data/Packungen_error_column.xls
|
87
85
|
- test/data/Packungen_error_missing1.xls
|
88
86
|
- test/data/Packungen_error_missing2.xls
|
89
87
|
- test/test_swissmedic-diff.rb
|
90
|
-
- .gemtest
|
91
88
|
homepage: https://github.com/zdavatz/swissmedic-diff
|
92
89
|
licenses: []
|
90
|
+
metadata: {}
|
93
91
|
post_install_message:
|
94
92
|
rdoc_options:
|
95
93
|
- --main
|
@@ -97,22 +95,20 @@ rdoc_options:
|
|
97
95
|
require_paths:
|
98
96
|
- lib
|
99
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
98
|
requirements:
|
102
99
|
- - ! '>='
|
103
100
|
- !ruby/object:Gem::Version
|
104
101
|
version: '0'
|
105
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
103
|
requirements:
|
108
104
|
- - ! '>='
|
109
105
|
- !ruby/object:Gem::Version
|
110
106
|
version: '0'
|
111
107
|
requirements: []
|
112
108
|
rubyforge_project: swissmedic-diff
|
113
|
-
rubygems_version:
|
109
|
+
rubygems_version: 2.2.1
|
114
110
|
signing_key:
|
115
|
-
specification_version:
|
111
|
+
specification_version: 4
|
116
112
|
summary: ! '* Compares two Excel Documents provided by Swissmedic and displays the
|
117
113
|
salient differences'
|
118
114
|
test_files:
|
Binary file
|