xls2odat 1.1.5

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.
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # Galdat2TextTest -- 23.08.2008 -- mhatakeyama@ywesee.com
4
+
5
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
6
+
7
+ require 'rubygems'
8
+ require 'test/unit'
9
+ require 'xls2odat'
10
+
11
+ class Xls2odatTest < Test::Unit::TestCase
12
+ def setup
13
+ @parser = Xls2odat.new
14
+ @data = File.expand_path 'data/data.xls', File.dirname(__FILE__)
15
+ @conf = File.expand_path 'data/conf.xls', File.dirname(__FILE__)
16
+ @conf_wrongformat = File.expand_path 'data/conf_wrongformat.xls', File.dirname(__FILE__)
17
+ @conf_noinformation = File.expand_path 'data/conf_noinformation.xls', File.dirname(__FILE__)
18
+ Spreadsheet.client_encoding = 'UTF-8'
19
+ @worksheet = Spreadsheet.open(@data).worksheet(0)
20
+ end
21
+ def test_read_config_wrongformat
22
+ assert_raise(RuntimeError){
23
+ @parser.read_config(@conf_wrongformat)
24
+ }
25
+ end
26
+ def test_read_config_noinformation
27
+ assert_raise(RuntimeError){
28
+ @parser.read_config(@conf_noinformation)
29
+ }
30
+ end
31
+ def test_read_config
32
+ @parser.read_config(@conf)
33
+
34
+ # config title
35
+ assert_equal 'Dixa.xls', @parser.instance_eval('@conf[0][0][0]')
36
+
37
+ # config size
38
+ assert_equal 59, @parser.instance_eval('@conf[0][1].length-1')
39
+ assert_equal nil, @parser.instance_eval('@conf[0][2]')
40
+ assert_equal 15, @parser.instance_eval('@conf[0][3].length-1')
41
+ assert_equal 26, @parser.instance_eval('@conf[0][4].length-1')
42
+
43
+ # values (sampling test)
44
+ assert_equal '01', @parser.instance_eval('@conf[0][1][1]')
45
+ assert_equal 'timestamp', @parser.instance_eval('@conf[0][1][2]')
46
+ assert_equal 1, @parser.instance_eval('@conf[0][1][3]')
47
+ assert_equal '204 031 871', @parser.instance_eval('@conf[0][1][4]')
48
+
49
+ assert_equal 'C+D', @parser.instance_eval('@conf[0][3][10]')
50
+
51
+ assert_equal 'Q,T,W,Z,AC,AF', @parser.instance_eval('@conf[0][4][20]')
52
+
53
+ # output filenames
54
+ assert_equal ['H01','H03','H04'], @parser.instance_eval('@out_filename')
55
+ end
56
+ def test_parse_data_error1
57
+ # read_config method must be called before parse_data method
58
+ assert_raise(RuntimeError){
59
+ @parser.parse_data(@data)
60
+ }
61
+ end
62
+ def test_parse_data_error2
63
+ # miss read undefined config informatin
64
+ assert_raise(RuntimeError){
65
+ @parser.read_config(@conf)
66
+ @parser.parse_data(@data,1)
67
+ }
68
+ end
69
+ def test_parse_data
70
+ row = @worksheet.row(1)
71
+ @parser.read_config(@conf)
72
+ @parser.parse_data(@data)
73
+ today = Date.today.to_s.split("-").join.to_s
74
+ file = File::mtime(@data).strftime("%Y%m%d")
75
+ result = "01|" + today + "|1|204031871|1||0|0|0||1178||||||1237|D||||||||29||||" + file + "|||2|||||||||||||||AAA|||||||||||"
76
+
77
+ assert_equal result, @parser.instance_eval('@out_data["H01"][0].join("|").to_s')
78
+ assert_equal "1234567890", @parser.instance_eval('@out_data["H01"][16][16]')
79
+
80
+ # prefix
81
+ assert_equal "prefix 1290", @parser.instance_eval('@out_data["H01"][18][16]')
82
+ end
83
+
84
+ # private methods
85
+ def test_column_s
86
+ assert_equal 0, @parser.send(:column_s,:filenr)
87
+ assert_equal 1, @parser.send(:column_s,:seqnr)
88
+ end
89
+ def test_column_a
90
+ assert_equal 0, @parser.send(:column_a,"A")
91
+ assert_equal 0, @parser.send(:column_a,"a")
92
+ assert_equal 1, @parser.send(:column_a,"B")
93
+ assert_equal 25, @parser.send(:column_a,"Z")
94
+ assert_equal 26, @parser.send(:column_a,"AA")
95
+ assert_equal 52, @parser.send(:column_a,"BA")
96
+ end
97
+ def test_cell
98
+ row = @worksheet.row(1)
99
+
100
+ assert_equal "1237", @parser.send(:cell, "A", row)
101
+ #assert_equal "012345", @parser.send(:cell, "H", row)
102
+ end
103
+ def test_analyzer
104
+ row = @worksheet.row(1)
105
+
106
+ # timestamp
107
+ today = Date.today.to_s.split("-").join.to_s
108
+ assert_equal today, @parser.send(:analyzer, "timestamp", row, @data)
109
+
110
+ # Datum der Tabelle
111
+ date = File::mtime(@data).strftime("%Y%m%d")
112
+ assert_equal date, @parser.send(:analyzer, 'Datum der Tabelle', row, @data)
113
+
114
+ # constant string value
115
+ assert_equal "A", @parser.send(:analyzer, '"A"', row, @data)
116
+
117
+ # if condition
118
+ assert_equal "300", @parser.send(:analyzer, "if A==1237 then 300", row, @data)
119
+ assert_equal "", @parser.send(:analyzer, "if A==1234 then 300", row, @data)
120
+ assert_equal "100", @parser.send(:analyzer, "if A==1234 then 300 if A==1237 then 100", row, @data)
121
+ assert_equal "200", @parser.send(:analyzer, "if A>1234 then 200", row, @data)
122
+ assert_equal "400", @parser.send(:analyzer, "if A>1239 then 100 if A<=1238 then 400", row, @data)
123
+ assert_equal "", @parser.send(:analyzer, "if A>1239 then 100 if A>1238 then 400", row, @data)
124
+ assert_equal "400", @parser.send(:analyzer, "if A==1234 then 300 else 400", row, @data)
125
+ assert_equal "H", @parser.send(:analyzer, 'if F=="in Auslistung" then "H"', row, @data)
126
+
127
+ # iteration
128
+ assert_equal "1237", @parser.send(:analyzer, "A,O,P", row, @data)
129
+ assert_equal "AAA", @parser.send(:analyzer, '"AAA","BBB"', row, @data)
130
+
131
+ # count-up value (Pharmacode)
132
+ assert_equal "123456789", @parser.send(:analyzer, "123 456 789", row, @data)
133
+
134
+ # refer to column data
135
+ assert_equal "1237", @parser.send(:analyzer, "A", row, @data)
136
+ assert_equal "1237 Aktiv", @parser.send(:analyzer, 'A+" "+B', row, @data)
137
+
138
+ # null and nil
139
+ assert_equal "", @parser.send(:analyzer, "", row, @data)
140
+ assert_equal "", @parser.send(:analyzer, nil, row, @data)
141
+
142
+ # conjunction of string and cell value
143
+ assert_equal "9991237", @parser.send(:analyzer, '"999"+A', row, @data)
144
+ end
145
+ end
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2010-12-16
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/xls2odat
7
+ lib/xls2odat.rb
8
+ test/test_xls2odat.rb
@@ -0,0 +1,57 @@
1
+ = xls2odat
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == DEVELOPERS:
26
+
27
+ After checking out the source, run:
28
+
29
+ $ rake newb
30
+
31
+ This task will install any missing dependencies, run the tests/specs,
32
+ and generate the RDoc.
33
+
34
+ == LICENSE:
35
+
36
+ (The MIT License)
37
+
38
+ Copyright (c) 2010 FIX
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining
41
+ a copy of this software and associated documentation files (the
42
+ 'Software'), to deal in the Software without restriction, including
43
+ without limitation the rights to use, copy, modify, merge, publish,
44
+ distribute, sublicense, and/or sell copies of the Software, and to
45
+ permit persons to whom the Software is furnished to do so, subject to
46
+ the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be
49
+ included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/xls2odat/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :cucumberfeatures
8
+ # Hoe.plugin :gem_prelude_sucks
9
+ # Hoe.plugin :inline
10
+ # Hoe.plugin :inline
11
+ # Hoe.plugin :manifest
12
+ # Hoe.plugin :newgem
13
+ # Hoe.plugin :racc
14
+ # Hoe.plugin :rubyforge
15
+ # Hoe.plugin :rubyforge
16
+ # Hoe.plugin :website
17
+
18
+ Hoe.spec 'xls2odat' do
19
+ # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
20
+ # you'll never have to touch them again!
21
+ # (delete this comment too, of course)
22
+
23
+ developer('Zeno R.R. Davatz', 'zdavatz@ywesee.com')
24
+
25
+ # self.rubyforge_name = 'xls2odatx' # if different than 'xls2odat'
26
+ end
27
+
28
+ # vim: syntax=ruby
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ abort "you need to write me"
@@ -0,0 +1,3 @@
1
+ class Xls2odat
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "xls2odat"
3
+
4
+ class TestXls2odat < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xls2odat
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 5
10
+ version: 1.1.5
11
+ platform: ruby
12
+ authors:
13
+ - Masaomi Hatakeyama, Zeno R.R. Davatz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-16 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hoe
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 47
30
+ segments:
31
+ - 2
32
+ - 8
33
+ - 0
34
+ version: 2.8.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: |-
38
+ xls2odat converts one or more XLS files to flat files so they can be
39
+ imported to a drugstore software or a pharmacy software in Switzerland.
40
+
41
+ xls2odat parses XLS files depending on a configuration XLS file, and
42
+ outputs the data separated by "|" symbol.
43
+ email:
44
+ - mhatakeyama@ywesee.com, zdavatz@ywesee.com
45
+ executables:
46
+ - xls2odat
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - Guide.txt
51
+ - History.txt
52
+ - Manifest.txt
53
+ - README.txt
54
+ - xls2odat/History.txt
55
+ - xls2odat/Manifest.txt
56
+ - xls2odat/README.txt
57
+ files:
58
+ - Guide.txt
59
+ - History.txt
60
+ - InstalledFiles
61
+ - LICENSE
62
+ - Manifest.txt
63
+ - README.txt
64
+ - Rakefile
65
+ - SetupConfig
66
+ - bin/xls2odat
67
+ - lib/xls2odat.rb
68
+ - setup.rb
69
+ - test/data/conf.xls
70
+ - test/data/conf_noinformation.xls
71
+ - test/data/conf_wrongformat.xls
72
+ - test/data/data.xls
73
+ - test/test_xls2odat.rb
74
+ - xls2odat/.autotest
75
+ - xls2odat/History.txt
76
+ - xls2odat/Manifest.txt
77
+ - xls2odat/README.txt
78
+ - xls2odat/Rakefile
79
+ - xls2odat/bin/xls2odat
80
+ - xls2odat/lib/xls2odat.rb
81
+ - xls2odat/test/test_xls2odat.rb
82
+ has_rdoc: true
83
+ homepage: http://scm.ywesee.com/?p=xls2odat/.git;a=summary
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --main
89
+ - README.txt
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project: xls2odat
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: xls2odat converts one or more XLS files to flat files so they can be imported to a drugstore software or a pharmacy software in Switzerland
117
+ test_files:
118
+ - test/test_xls2odat.rb