condition 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/condition/param.rb +17 -34
- data/lib/condition/param_item.rb +10 -0
- data/lib/condition/reader/roo_reader.rb +38 -0
- data/lib/condition/storage/mongo.rb +11 -2
- data/lib/condition/version.rb +1 -1
- data/lib/condition.rb +1 -0
- data/spec/condition_spec.rb +6 -2
- data/spec/files/mongo.ods +0 -0
- data/spec/files/t_user.ods +0 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 662e70bdaa099817376d9934c1146469274e7646
|
4
|
+
data.tar.gz: 34fc6074209e62d7fb346b507f04ed32ff39312b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3dac4a43ae5960261295cd69ddcaa4925cf5f55a7c52dfd4bd6facf33ad1514411e460c78a85052e300d2bf0d35d7bb8ecdd470d901b02463653dd077bb628
|
7
|
+
data.tar.gz: 64fc5bf5eb48e000fdb0052258ffe193a11811ca04c793deb594c4f96af8b805b4e1ba3e98ef1a4a1c6bd37a394f79851fc8a7bccd6675f2b508afad84cf256b
|
data/README.md
CHANGED
data/lib/condition/param.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require 'roo'
|
3
|
-
|
4
2
|
module Condition
|
5
3
|
class Param
|
4
|
+
@@reader = nil
|
5
|
+
|
6
|
+
def self.set_reader(reader)
|
7
|
+
@@reader = reader
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_reader()
|
11
|
+
if @@reader.nil?
|
12
|
+
@@reader = Condition::Reader::RooReader.new
|
13
|
+
end
|
14
|
+
@@reader
|
15
|
+
end
|
16
|
+
|
6
17
|
def initialize(path, sheet_index=0)
|
7
|
-
blocks = read_sheet(path, sheet_index)
|
18
|
+
blocks = Condition::Param.get_reader().read_sheet(path, sheet_index)
|
8
19
|
@item_map = {}
|
9
20
|
item_list = []
|
10
21
|
blocks.each do |rows|
|
@@ -17,36 +28,6 @@ module Condition
|
|
17
28
|
end
|
18
29
|
end
|
19
30
|
|
20
|
-
def read_sheet(path, sheet_index)
|
21
|
-
ss = Roo::Spreadsheet.open(path)
|
22
|
-
ss.default_sheet = ss.sheets[sheet_index]
|
23
|
-
row_index = 1
|
24
|
-
res = []
|
25
|
-
while true
|
26
|
-
break if nil == ss.cell(row_index, 1)
|
27
|
-
table = []
|
28
|
-
while true
|
29
|
-
row = read_row(ss, row_index)
|
30
|
-
row_index += 1
|
31
|
-
break if 0 == row.size
|
32
|
-
table << row
|
33
|
-
end
|
34
|
-
res << table
|
35
|
-
end
|
36
|
-
res
|
37
|
-
end
|
38
|
-
|
39
|
-
def read_row(ss, row_index)
|
40
|
-
column_index = 1
|
41
|
-
result = []
|
42
|
-
while true
|
43
|
-
value = ss.cell(row_index, column_index)
|
44
|
-
return result if nil == value
|
45
|
-
result << value
|
46
|
-
column_index += 1
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
31
|
def item(name)
|
51
32
|
@item_map[name.to_sym]
|
52
33
|
end
|
@@ -75,11 +56,13 @@ module Condition
|
|
75
56
|
|
76
57
|
def post(storage)
|
77
58
|
@item_map.each_value do |item|
|
59
|
+
item.clear_used_values
|
78
60
|
list = storage.all(item)
|
79
61
|
list.each do |line|
|
80
62
|
item.check_line(line)
|
81
63
|
end
|
64
|
+
raise "#{item.name} not exists row" if item.is_remain_value
|
82
65
|
end
|
83
66
|
end
|
84
67
|
end
|
85
|
-
end
|
68
|
+
end
|
data/lib/condition/param_item.rb
CHANGED
@@ -12,6 +12,7 @@ module Condition
|
|
12
12
|
@keys = []
|
13
13
|
@params = {}
|
14
14
|
@refs = []
|
15
|
+
@used_values = []
|
15
16
|
body.each do |row|
|
16
17
|
index = 0
|
17
18
|
key = row[0].to_sym
|
@@ -28,6 +29,14 @@ module Condition
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
32
|
+
def clear_used_values
|
33
|
+
@used_values = []
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_remain_value
|
37
|
+
@values.size > @used_values.size
|
38
|
+
end
|
39
|
+
|
31
40
|
def calc_item(item, index, key)
|
32
41
|
if '#NULL' == item
|
33
42
|
nil
|
@@ -147,6 +156,7 @@ module Condition
|
|
147
156
|
targetFlag = false if whereKeyFlag && !match
|
148
157
|
end
|
149
158
|
if targetFlag && matchFlag
|
159
|
+
@used_values << value
|
150
160
|
return true
|
151
161
|
elsif !targetFlag
|
152
162
|
return false
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'roo'
|
3
|
+
|
4
|
+
module Condition
|
5
|
+
module Reader
|
6
|
+
class RooReader
|
7
|
+
def read_sheet(path, sheet_index)
|
8
|
+
ss = Roo::Spreadsheet.open(path)
|
9
|
+
ss.default_sheet = ss.sheets[sheet_index]
|
10
|
+
row_index = 1
|
11
|
+
res = []
|
12
|
+
while true
|
13
|
+
break if nil == ss.cell(row_index, 1)
|
14
|
+
table = []
|
15
|
+
while true
|
16
|
+
row = read_row(ss, row_index)
|
17
|
+
row_index += 1
|
18
|
+
break if 0 == row.size
|
19
|
+
table << row
|
20
|
+
end
|
21
|
+
res << table
|
22
|
+
end
|
23
|
+
res
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_row(ss, row_index)
|
27
|
+
column_index = 1
|
28
|
+
result = []
|
29
|
+
while true
|
30
|
+
value = ss.cell(row_index, column_index)
|
31
|
+
return result if nil == value
|
32
|
+
result << value
|
33
|
+
column_index += 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -8,7 +8,16 @@ module Condition
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def all(param_item)
|
11
|
-
@db[param_item.name].find()
|
11
|
+
list = @db[param_item.name].find()
|
12
|
+
res = []
|
13
|
+
list.each do |row|
|
14
|
+
hash = {}
|
15
|
+
row.each do |k, v|
|
16
|
+
hash[k.to_sym] = v
|
17
|
+
end
|
18
|
+
res << hash
|
19
|
+
end
|
20
|
+
res
|
12
21
|
end
|
13
22
|
|
14
23
|
def delete(param_item)
|
@@ -29,4 +38,4 @@ module Condition
|
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
32
|
-
end
|
41
|
+
end
|
data/lib/condition/version.rb
CHANGED
data/lib/condition.rb
CHANGED
data/spec/condition_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Condition do
|
|
6
6
|
DB << "CREATE TABLE t_user(user_id BIGINT, user_name TEXT, login_ts TIMESTAMPTZ NOT NULL)"
|
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
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it 'pre and post' do
|
11
11
|
storage = Condition::Storage::Db.new(DB)
|
12
12
|
param = Condition::Param.new(FILES + '/t_user.ods')
|
@@ -14,6 +14,10 @@ describe Condition do
|
|
14
14
|
param.pre(storage, default)
|
15
15
|
param = Condition::Param.new(FILES + '/t_user.ods', 1)
|
16
16
|
param.post(storage)
|
17
|
+
param = Condition::Param.new(FILES + '/t_user.ods', 4)
|
18
|
+
expect { param.post(storage) }.to raise_error
|
19
|
+
param = Condition::Param.new(FILES + '/t_user.ods', 5)
|
20
|
+
expect { param.post(storage) }.to raise_error
|
17
21
|
end
|
18
22
|
|
19
23
|
it 'pre and params' do
|
@@ -60,7 +64,7 @@ describe Condition do
|
|
60
64
|
param = Condition::Param.new(FILES + '/mongo.ods')
|
61
65
|
default = Condition::Param.new(FILES + '/mongo.ods', 2)
|
62
66
|
param.pre(storage, default)
|
63
|
-
param = Condition::Param.new(FILES + '/
|
67
|
+
param = Condition::Param.new(FILES + '/mongo.ods', 1)
|
64
68
|
param.post(storage)
|
65
69
|
end
|
66
70
|
end
|
data/spec/files/mongo.ods
CHANGED
Binary file
|
data/spec/files/t_user.ods
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aoyagikouhei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- lib/condition.rb
|
153
153
|
- lib/condition/param.rb
|
154
154
|
- lib/condition/param_item.rb
|
155
|
+
- lib/condition/reader/roo_reader.rb
|
155
156
|
- lib/condition/storage/db.rb
|
156
157
|
- lib/condition/storage/mongo.rb
|
157
158
|
- lib/condition/version.rb
|
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
180
|
version: '0'
|
180
181
|
requirements: []
|
181
182
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.1.
|
183
|
+
rubygems_version: 2.1.9
|
183
184
|
signing_key:
|
184
185
|
specification_version: 4
|
185
186
|
summary: Condition Test
|