swissmedic-diff 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swissmedic-diff (0.1.4)
4
+ swissmedic-diff (0.1.5)
5
+ nokogiri
6
+ rubyXL
7
+ rubyzip
5
8
  spreadsheet
6
9
 
7
10
  GEM
@@ -10,19 +13,24 @@ GEM
10
13
  ansi (1.4.3)
11
14
  builder (3.2.2)
12
15
  hashie (2.0.5)
13
- hoe (3.7.2)
16
+ hoe (3.7.4)
14
17
  rake (>= 0.8, < 11.0)
15
- minitest (5.1.0)
18
+ mini_portile (0.5.2)
19
+ minitest (5.2.1)
16
20
  minitest-reporters (1.0.0)
17
21
  ansi
18
22
  builder
19
23
  minitest (>= 5.0)
20
24
  powerbar
25
+ nokogiri (1.6.0)
26
+ mini_portile (~> 0.5.0)
21
27
  powerbar (1.0.11)
22
28
  ansi (~> 1.4.0)
23
29
  hashie (>= 1.1.0)
24
- rake (10.1.0)
30
+ rake (10.1.1)
25
31
  ruby-ole (1.2.11.7)
32
+ rubyXL (1.2.10)
33
+ rubyzip (0.9.9)
26
34
  spreadsheet (0.9.6)
27
35
  ruby-ole (>= 1.0)
28
36
 
data/History.txt CHANGED
@@ -1,4 +1,11 @@
1
- === 0.1.5 / 11.12.2010
1
+ === 0.1.6 / 14.01.2014
2
+
3
+ * Added test/data/Packungen-2014.xlsx
4
+ * Added missing dependencies for rubyXL
5
+ * Moved VERSION to separate file
6
+ * Use rubyXL for xslx files
7
+
8
+ === 0.1.5 / 11.12.2013
2
9
 
3
10
  * Updated tests as we no longer raise an error
4
11
  * Update to spreadsheet 0.9.6
data/Manifest.txt CHANGED
@@ -9,9 +9,11 @@ README.txt
9
9
  Rakefile
10
10
  bin/swissmedic-diff
11
11
  lib/swissmedic-diff.rb
12
+ lib/version.rb
12
13
  setup.rb
13
14
  swissmedic-diff.gemspec
14
15
  test/data/Packungen-2013.10.14.xls
16
+ test/data/Packungen-2014.xlsx
15
17
  test/data/Packungen.older.xls
16
18
  test/data/Packungen.xls
17
19
  test/data/Packungen_error_column.xls
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'ostruct'
6
6
  require 'spreadsheet'
7
+ require 'rubyXL'
7
8
 
8
9
  #= diff command (compare two xls fles) for swissmedic xls file.
9
10
  #
@@ -17,8 +18,6 @@ require 'spreadsheet'
17
18
  #License:: GPLv2.0 Compliance
18
19
  #Source:: http://scm.ywesee.com/?p=swissmedic-diff/.git;a=summary
19
20
  class SwissmedicDiff
20
- VERSION = '0.1.5'
21
-
22
21
  module Diff
23
22
  COLUMNS = [ :iksnr, :seqnr, :name_base, :company,
24
23
  :index_therapeuticus, :atc_class, :production_science,
@@ -97,7 +96,11 @@ class SwissmedicDiff
97
96
  @diff.changes = changes = {}
98
97
  @diff.newest_rows = newest_rows
99
98
  Spreadsheet.client_encoding = 'UTF-8'
100
- tbook = Spreadsheet.open(target)
99
+ if File.extname(target).eql?('.xlsx')
100
+ tbook = RubyXL::Parser.parse(File.expand_path(target))
101
+ else
102
+ tbook = Spreadsheet.open(target)
103
+ end
101
104
  sheet = tbook.worksheet(0)
102
105
  if new_column = cell(sheet.row(2), COLUMNS.size)
103
106
  raise "New column #{COLUMNS.size} (#{new_column})"
@@ -178,7 +181,11 @@ class SwissmedicDiff
178
181
  [known_regs, known_seqs, known_pacs, newest_rows]
179
182
  end
180
183
  def _known_data(latest, known_regs, known_seqs, known_pacs, newest_rows)
181
- lbook = Spreadsheet.open(latest)
184
+ if File.extname(latest).eql?('.xlsx')
185
+ lbook = RubyXL::Parser.parse(File.expand_path(latest)).worksheets[0]
186
+ else
187
+ lbook = Spreadsheet.open(latest)
188
+ end
182
189
  idx, prr, prp = nil
183
190
  multiples = {}
184
191
  each_valid_row(lbook) { |row|
@@ -290,11 +297,18 @@ class SwissmedicDiff
290
297
  #return ::
291
298
  def each_valid_row(spreadsheet)
292
299
  skipRows = rows_to_skip(spreadsheet)
293
- worksheet = spreadsheet.worksheet(0)
294
- worksheet.each(skipRows) {
300
+ if spreadsheet.class.eql?(RubyXL::Worksheet)
301
+ worksheet = spreadsheet
302
+ else
303
+ worksheet = spreadsheet.worksheet(0)
304
+ end
305
+ row_nr = 0
306
+ worksheet.each() {
295
307
  |row|
308
+ row_nr += 1
309
+ next if row_nr <= skipRows
296
310
  if row.size < COLUMNS.size/2 || row.select{|val| val==nil}.size > COLUMNS.size/2
297
- $stdout.puts "Data missing in \n(line " + (row.idx+1).to_s + "): " + row.join(", ").to_s + "\n"
311
+ $stdout.puts "Data missing in \n(line " + (row_nr).to_s + "): " + row.join(", ").to_s + "\n"
298
312
  next
299
313
  end
300
314
  next if (cell(row, column(:production_science)) == 'Tierarzneimittel')
@@ -309,7 +323,11 @@ class SwissmedicDiff
309
323
  # Packungen.xls of swissmedic before October 2013 had 3 leading rows
310
324
  # Packungen.xls of swissmedic after October 2013 have 4 leading rows
311
325
  j = 0
312
- j += 1 while spreadsheet.worksheet(0).row(j)[0].to_i == 0
326
+ if spreadsheet.class.eql?(RubyXL::Worksheet)
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
313
331
  j
314
332
  end
315
333
 
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ class SwissmedicDiff
2
+ VERSION = '0.1.6'
3
+ end
@@ -1,6 +1,8 @@
1
+ require File.expand_path('../lib/version', __FILE__)
2
+
1
3
  spec = Gem::Specification.new do |s|
2
4
  s.name = "swissmedic-diff"
3
- s.version = "0.1.4"
5
+ s.version = SwissmedicDiff::VERSION
4
6
  s.summary = "Find out what Products have changed on the swiss healthcare market"
5
7
  s.description = "Compares two Excel Documents provided by Swissmedic and displays the salient differences"
6
8
  s.author = "Hannes Wyss, Masaomi Hatakeyama"
@@ -13,6 +15,9 @@ spec = Gem::Specification.new do |s|
13
15
  Dir.glob('test/data/*.xls')
14
16
  s.test_file = "test/test_swissmedic-diff.rb"
15
17
  s.executables << 'swissmedic-diff'
18
+ s.add_dependency('rubyXL')
19
+ s.add_dependency('nokogiri')
20
+ s.add_dependency('rubyzip')
16
21
  s.add_dependency('spreadsheet')
17
22
  s.add_development_dependency "hoe"
18
23
  s.add_development_dependency "minitest"
Binary file
@@ -6,6 +6,7 @@ $: << File.expand_path("../lib", File.dirname(__FILE__))
6
6
 
7
7
  require 'minitest/autorun'
8
8
  require 'swissmedic-diff'
9
+ require 'pp'
9
10
 
10
11
  module ODDB
11
12
  class SwissmedicPluginTest < Minitest::Test
@@ -25,27 +26,31 @@ module ODDB
25
26
  File.dirname(__FILE__)
26
27
  @workbook = Spreadsheet.open(@data)
27
28
  end
28
-
29
+ # This is not a unit test as it takes way too long (> 1 minute)
30
+ # Instead it might just tell you how to test with real data
31
+ def test_diff_xls_and_xlsx
32
+ @diff = SwissmedicDiff.new
33
+ last_month = File.expand_path 'data/Packungen.xls', File.dirname(__FILE__)
34
+ this_month = File.expand_path 'data/Packungen-2014.xlsx', File.dirname(__FILE__)
35
+ result = @diff.diff last_month, this_month, [:atc_class, :sequence_date]
36
+ assert(result.changes.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
37
+ assert(result.news.first.index('00275'), "Should find 00275 in news")
38
+ assert(result.news.first.index('00277') == nil, "Should not find 00277 in news")
39
+ assert(result.news.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
40
+ end
41
+
29
42
  # This is not a unit test as it takes way too long (> 1 minute)
30
43
  # Instead it might just tell you how to test with real data
31
44
  def test_real_diff
32
- require 'pp'
33
45
  @diff = SwissmedicDiff.new
34
46
  last_month = File.expand_path 'data/Packungen-2013.08.16.xls', File.dirname(__FILE__)
35
47
  this_month = File.expand_path 'data/Packungen-2013.11.04.xls', File.dirname(__FILE__)
36
48
  result = @diff.diff last_month, this_month, [:atc_class, :sequence_date]
37
- pp result.news.first
38
- pp result.news.last
39
- pp result.updates.first
40
- pp result.replacements.first
41
- # assert(result.changes.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
42
- # assert(result.news.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
43
- # assert(result.news.flatten.index('00277') == nil, "Should not find 00277 in news")
44
- pp result.news.size
45
- pp result.updates.size
46
- pp result.replacements.size
49
+ assert(result.changes.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
50
+ assert(result.news.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
51
+ assert(result.news.flatten.index('00277') == nil, "Should not find 00277 in news")
47
52
  end if false
48
-
53
+
49
54
  def test_iterate
50
55
  diff = SwissmedicDiff.new
51
56
  strings = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swissmedic-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
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-11 00:00:00.000000000 Z
12
+ date: 2014-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -76,9 +76,11 @@ files:
76
76
  - Rakefile
77
77
  - bin/swissmedic-diff
78
78
  - lib/swissmedic-diff.rb
79
+ - lib/version.rb
79
80
  - setup.rb
80
81
  - swissmedic-diff.gemspec
81
82
  - test/data/Packungen-2013.10.14.xls
83
+ - test/data/Packungen-2014.xlsx
82
84
  - test/data/Packungen.older.xls
83
85
  - test/data/Packungen.xls
84
86
  - test/data/Packungen_error_column.xls