condition 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/condition/reader/convert_sheet.rb +22 -0
- data/lib/condition/reader/roo_reader.rb +4 -0
- data/lib/condition/version.rb +1 -1
- data/spec/condition_spec.rb +12 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61d962f0e11bd728b3c8ae8ccab732e6b9533d03
|
4
|
+
data.tar.gz: 4711e5312cbbf60877a37e227adf323b3cdbcdbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0eced2d36943454a86a5a9f42f07c1be28a552448aa00fd9799a70b8ca6feb91cfd16800b20c36976947aff41d388458530264cdf5db29f3d9899be24b07190
|
7
|
+
data.tar.gz: 4855af721f9135bf72aa8b12dd4e561f55c0b13b99f6ba9f03dc89021319ce6db6d31d1dd041155cc64b07df3c66dbfd4c8e2e16171ee58e2ad7149e1c709e38
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'json'
|
3
|
+
require 'roo'
|
3
4
|
|
4
5
|
module Condition
|
5
6
|
module Reader
|
@@ -12,6 +13,27 @@ module Condition
|
|
12
13
|
def convert(path, sheet_index, name)
|
13
14
|
@redis.set(name, JSON.generate(@reader.read_sheet(path, sheet_index)))
|
14
15
|
end
|
16
|
+
|
17
|
+
def convert_file(path, prefix: nil)
|
18
|
+
name = File.basename(path, ".*")
|
19
|
+
ss = Roo::Spreadsheet.open(path)
|
20
|
+
ss.sheets.each do |it|
|
21
|
+
ss.default_sheet = it
|
22
|
+
blocks = @reader.read(ss)
|
23
|
+
key = "#{name}_#{it}"
|
24
|
+
key = "#{prefix}_#{key}" if !prefix.nil?
|
25
|
+
@redis.set(key, JSON.generate(blocks))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_dir(path, with_dir_name: true)
|
30
|
+
basename = File.basename(path)
|
31
|
+
Dir::entries(path).each do |f|
|
32
|
+
next if "." == f || ".." == f || /^\.~lock\.[^.]+\.ods.$/ =~ f
|
33
|
+
prefix = with_dir_name ? basename : nil
|
34
|
+
convert_file("#{path}/#{f}", prefix: prefix)
|
35
|
+
end
|
36
|
+
end
|
15
37
|
end
|
16
38
|
end
|
17
39
|
end
|
data/lib/condition/version.rb
CHANGED
data/spec/condition_spec.rb
CHANGED
@@ -7,12 +7,8 @@ describe Condition do
|
|
7
7
|
DB << "CREATE TABLE t_test(id BIGINT, name TEXT, flag BOOLEAN, ts TIMESTAMPTZ, iary BIGINT[], tary TEXT[], test_name TEXT NOT NULL)"
|
8
8
|
|
9
9
|
converter = Condition::Reader::ConvertSheet.new(REDIS)
|
10
|
-
converter.
|
11
|
-
converter.
|
12
|
-
converter.convert(FILES + '/t_user.ods', 2, 'params')
|
13
|
-
converter.convert(FILES + '/t_user.ods', 3, 'default')
|
14
|
-
converter.convert(FILES + '/t_user.ods', 4, 'post_condition2')
|
15
|
-
converter.convert(FILES + '/t_user.ods', 5, 'post_condition3')
|
10
|
+
converter.convert_dir(FILES, with_dir_name: false)
|
11
|
+
converter.convert_dir(FILES)
|
16
12
|
end
|
17
13
|
|
18
14
|
it 'pre and post' do
|
@@ -80,14 +76,14 @@ describe Condition do
|
|
80
76
|
reader = Condition::Reader::RedisReader.new(REDIS)
|
81
77
|
Condition::Param.set_reader(reader)
|
82
78
|
storage = Condition::Storage::Db.new(DB)
|
83
|
-
param = Condition::Param.new('
|
84
|
-
default = Condition::Param.new('
|
79
|
+
param = Condition::Param.new('t_user_pre')
|
80
|
+
default = Condition::Param.new('t_user_default')
|
85
81
|
param.pre(storage, default)
|
86
|
-
param = Condition::Param.new('
|
82
|
+
param = Condition::Param.new('t_user_post')
|
87
83
|
param.post(storage)
|
88
|
-
param = Condition::Param.new('
|
84
|
+
param = Condition::Param.new('t_user_post2')
|
89
85
|
expect { param.post(storage) }.to raise_error
|
90
|
-
param = Condition::Param.new('
|
86
|
+
param = Condition::Param.new('t_user_post3')
|
91
87
|
expect { param.post(storage) }.to raise_error
|
92
88
|
end
|
93
89
|
|
@@ -96,17 +92,14 @@ describe Condition do
|
|
96
92
|
Condition::Param.set_reader(nil)
|
97
93
|
|
98
94
|
storage = Condition::Storage::Db.new(DB)
|
99
|
-
param = Condition::Param.new('
|
100
|
-
default = Condition::Param.new('
|
95
|
+
param = Condition::Param.new('files_t_user_pre', reader: reader)
|
96
|
+
default = Condition::Param.new('files_t_user_default', reader: reader)
|
101
97
|
param.pre(storage, default)
|
102
|
-
param = Condition::Param.new('
|
98
|
+
param = Condition::Param.new('files_t_user_post', reader: reader)
|
103
99
|
param.post(storage)
|
104
|
-
param = Condition::Param.new('
|
100
|
+
param = Condition::Param.new('files_t_user_post2', reader: reader)
|
105
101
|
expect { param.post(storage) }.to raise_error
|
106
|
-
param = Condition::Param.new('
|
107
|
-
expect { param.post(storage) }.to raise_error
|
108
|
-
|
109
|
-
param = Condition::Param.new(FILES + '/t_user.ods', 5)
|
102
|
+
param = Condition::Param.new('files_t_user_post3', reader: reader)
|
110
103
|
expect { param.post(storage) }.to raise_error
|
111
104
|
end
|
112
105
|
|