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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f6e6b63b389476aeff5e4d95247e0d5d35629ae
4
- data.tar.gz: bc05b5b4eaa8c7c6962a686a39c185aa642185ce
3
+ metadata.gz: 61d962f0e11bd728b3c8ae8ccab732e6b9533d03
4
+ data.tar.gz: 4711e5312cbbf60877a37e227adf323b3cdbcdbd
5
5
  SHA512:
6
- metadata.gz: 91d70e0ac79e93af4d89617efdb6067623d384665e7a7f688095fa42344592258d3c888f480573d92e10b9885dac00d6b1c45431c0ae263b5131796c02760fd1
7
- data.tar.gz: 57729586f297cb315949dfdcf672fe61031e2b0621e863624ca38abafbdb500a311e57b1675f16ecb00d05678db2522210c65b4ce2465f99f6f6fcc1e9e0e51b
6
+ metadata.gz: a0eced2d36943454a86a5a9f42f07c1be28a552448aa00fd9799a70b8ca6feb91cfd16800b20c36976947aff41d388458530264cdf5db29f3d9899be24b07190
7
+ data.tar.gz: 4855af721f9135bf72aa8b12dd4e561f55c0b13b99f6ba9f03dc89021319ce6db6d31d1dd041155cc64b07df3c66dbfd4c8e2e16171ee58e2ad7149e1c709e38
data/README.md CHANGED
@@ -30,6 +30,9 @@ TODO: Write usage instructions here
30
30
 
31
31
  ## Changes
32
32
 
33
+ 2013-12-12 0.0.19
34
+ add convert file to redis
35
+
33
36
  2013-12-12 0.0.18
34
37
  add eval check
35
38
 
@@ -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
@@ -7,6 +7,10 @@ module Condition
7
7
  def read_sheet(path, sheet_index)
8
8
  ss = Roo::Spreadsheet.open(path)
9
9
  ss.default_sheet = ss.sheets[sheet_index]
10
+ read(ss)
11
+ end
12
+
13
+ def read(ss)
10
14
  row_index = 1
11
15
  res = []
12
16
  while true
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Condition
4
- VERSION = "0.0.18"
4
+ VERSION = "0.0.19"
5
5
  end
@@ -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.convert(FILES + '/t_user.ods', 0, 'pre_condition')
11
- converter.convert(FILES + '/t_user.ods', 1, 'post_condition1')
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('pre_condition')
84
- default = Condition::Param.new('default')
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('post_condition1')
82
+ param = Condition::Param.new('t_user_post')
87
83
  param.post(storage)
88
- param = Condition::Param.new('post_condition2')
84
+ param = Condition::Param.new('t_user_post2')
89
85
  expect { param.post(storage) }.to raise_error
90
- param = Condition::Param.new('post_condition3')
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('pre_condition', reader: reader)
100
- default = Condition::Param.new('default', reader: reader)
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('post_condition1', reader: reader)
98
+ param = Condition::Param.new('files_t_user_post', reader: reader)
103
99
  param.post(storage)
104
- param = Condition::Param.new('post_condition2', reader: reader)
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('post_condition3', reader: reader)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condition
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - aoyagikouhei