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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb3eb3d5b4acee42ce9121918d0d613ebaed8365
4
- data.tar.gz: 03e56423e7cbe951ee1689a16d06fc313538bcd3
3
+ metadata.gz: 662e70bdaa099817376d9934c1146469274e7646
4
+ data.tar.gz: 34fc6074209e62d7fb346b507f04ed32ff39312b
5
5
  SHA512:
6
- metadata.gz: 70b5494197bf56f1014513e8f4336fe624f3798aa9ff3d59705dbb73fe2f9840df3fb93bf5fad704aae1a59ce7dcfef70b2ee8d7a6bc721e9fa44f20a695f2ac
7
- data.tar.gz: 5d6456c00c1cfca1854fb4463eb4e96c921d637c5155282b822ead45c9bfe794e9fe2529d705b93e4d890d04b905b4830c9090e2b32369fac2774affbab22c2d
6
+ metadata.gz: db3dac4a43ae5960261295cd69ddcaa4925cf5f55a7c52dfd4bd6facf33ad1514411e460c78a85052e300d2bf0d35d7bb8ecdd470d901b02463653dd077bb628
7
+ data.tar.gz: 64fc5bf5eb48e000fdb0052258ffe193a11811ca04c793deb594c4f96af8b805b4e1ba3e98ef1a4a1c6bd37a394f79851fc8a7bccd6675f2b508afad84cf256b
data/README.md CHANGED
@@ -30,6 +30,10 @@ TODO: Write usage instructions here
30
30
 
31
31
  ## Changes
32
32
 
33
+ 2013-12-06 0.0.16
34
+ modify mongo key to symbol
35
+ modify check no used line in expectations
36
+
33
37
  2013-12-03 0.0.15
34
38
  add present and regexp check
35
39
 
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Condition
4
- VERSION = "0.0.15"
4
+ VERSION = "0.0.16"
5
5
  end
data/lib/condition.rb CHANGED
@@ -3,3 +3,4 @@
3
3
  require "condition/version"
4
4
  require "condition/param_item"
5
5
  require "condition/param"
6
+ require "condition/reader/roo_reader"
@@ -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 + '/t_user.ods', 1)
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
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.15
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-03 00:00:00.000000000 Z
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.10
183
+ rubygems_version: 2.1.9
183
184
  signing_key:
184
185
  specification_version: 4
185
186
  summary: Condition Test