condition 0.0.1 → 0.0.2

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: b3db8b51554104a64aa91a45869f59070dbba10e
4
- data.tar.gz: 317311cccf4ae7232a441d1545eb01caa890024d
3
+ metadata.gz: 2cc74fd455a5c5272d28fdf6ed278b6b3f2790dd
4
+ data.tar.gz: 8a7cffd879fd0c3cab7c0f77490896e0f1645edf
5
5
  SHA512:
6
- metadata.gz: 9223a6577b9db8f6846699a0e415bde33bedfc271f428a52fe60deb24e2b20df80910b505bcf5caf4484b1a62760904fb51ed5bb97ebce59dff7eb57bdbe9764
7
- data.tar.gz: 94652a228b56e34a4ee07bcb81d4b251ee385651ac9f02ae68fb44b28557ab4f0381e98e029029bd8825dfd843d73ffc27a0785a09b43698ccf2f5ae390381bf
6
+ metadata.gz: b01d271d559b2d76f8f5ef336e8a63f86c396ab3b5e945079f82ea96e8133ce01e3cbdb0cbc149bf3200d562b5c26d39ed5fd1dd0af75d57cf6e7140e37baa61
7
+ data.tar.gz: eadf6a040442e6ad2be58c69a6064a6c0a5d0830b90f292938e94cf24ed219dc7adfe615937a54f2da208a812bd56a24d10935396483c7da9ebb16d895973e36
data/README.md CHANGED
@@ -27,3 +27,12 @@ TODO: Write usage instructions here
27
27
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
28
  4. Push to the branch (`git push origin my-new-feature`)
29
29
  5. Create new Pull Request
30
+
31
+ ## Changes
32
+
33
+ 2013-04-11 0.0.2
34
+ add param, param_item
35
+ delete pre, post, reader, table
36
+
37
+ 2013-04-10 0.0.1
38
+ first release
@@ -0,0 +1,76 @@
1
+ # coding: utf-8
2
+ require 'roo'
3
+
4
+ module Condition
5
+ class Param
6
+ def initialize(path, sheet_index=0)
7
+ blocks = read_sheet(path, sheet_index)
8
+ @item_map = {}
9
+ blocks.each do |rows|
10
+ item = Condition::ParamItem.new(rows)
11
+ @item_map[item.name] = item
12
+ end
13
+ end
14
+
15
+ def read_sheet(path, sheet_index)
16
+ ss = Roo::Spreadsheet.open(path)
17
+ ss.default_sheet = ss.sheets[sheet_index]
18
+ row_index = 1
19
+ res = []
20
+ while true
21
+ break if nil == ss.cell(row_index, 1)
22
+ table = []
23
+ while true
24
+ row = read_row(ss, row_index)
25
+ row_index += 1
26
+ break if 0 == row.size
27
+ table << row
28
+ end
29
+ res << table
30
+ end
31
+ res
32
+ end
33
+
34
+ def read_row(ss, row_index)
35
+ column_index = 1
36
+ result = []
37
+ while true
38
+ value = ss.cell(row_index, column_index)
39
+ return result if nil == value
40
+ result << value
41
+ column_index += 1
42
+ end
43
+ end
44
+
45
+ def get(name)
46
+ @item_map[name].values
47
+ end
48
+
49
+ def get_one(name)
50
+ @item_map[name].value
51
+ end
52
+
53
+ def check(name, data)
54
+ item = @item_map[name]
55
+ data.each do |line|
56
+ item.check_line(line)
57
+ end
58
+ end
59
+
60
+ def pre(db)
61
+ @item_map.each_value do |item|
62
+ item.delete(db)
63
+ item.insert(db)
64
+ end
65
+ end
66
+
67
+ def post(db)
68
+ @item_map.each_value do |item|
69
+ list = item.all(db)
70
+ list.each do |line|
71
+ item.check_line(line)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -2,9 +2,9 @@
2
2
  require 'time'
3
3
 
4
4
  module Condition
5
- class Table
5
+ class ParamItem
6
6
  def initialize(rows)
7
- @table_name = rows[0][0]
7
+ @name = rows[0][0]
8
8
  @keys = rows[0].size > 1 ? rows[0][1..rows.size - 1] : []
9
9
  body = rows[1..rows.size - 1]
10
10
  @values = []
@@ -24,16 +24,28 @@ module Condition
24
24
  end
25
25
  end
26
26
 
27
+ def name
28
+ @name
29
+ end
30
+
31
+ def value
32
+ @values[0]
33
+ end
34
+
35
+ def values
36
+ @values
37
+ end
38
+
27
39
  def all(db)
28
- db["SELECT * FROM #{@table_name}"].all
40
+ db["SELECT * FROM #{@name}"].all
29
41
  end
30
42
 
31
43
  def delete(db)
32
- db["DELETE FROM #{@table_name}"].delete
44
+ db["DELETE FROM #{@name}"].delete
33
45
  end
34
46
 
35
47
  def insert(db)
36
- ds = db[@table_name.to_sym].prepare(:insert, :insert_with_name, @params)
48
+ ds = db[@name.to_sym].prepare(:insert, :insert_with_name, @params)
37
49
  @values.each do |it|
38
50
  ds.call(it)
39
51
  end
@@ -63,7 +75,7 @@ module Condition
63
75
  elsif !targetFlag
64
76
  return false
65
77
  else
66
- raise "#{@table_name} not match " + real.to_s
78
+ raise "#{@name} not match " + real.to_s
67
79
  end
68
80
  end
69
81
 
@@ -71,7 +83,7 @@ module Condition
71
83
  @values.each do |value|
72
84
  return if check_value(real, value)
73
85
  end
74
- raise "#{@table_name} not found " + real.to_s
86
+ raise "#{@name} not found " + real.to_s
75
87
  end
76
88
 
77
89
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Condition
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/condition.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require "condition/version"
4
- require "condition/reader"
5
- require "condition/table"
6
- require "condition/pre"
7
- require "condition/post"
4
+ require "condition/param_item"
5
+ require "condition/param"
@@ -6,9 +6,21 @@ describe Condition do
6
6
  end
7
7
 
8
8
  it 'pre and post' do
9
- pre = Condition::Pre.new(FILES + '/t_user.ods')
10
- pre.exec(DB)
11
- post = Condition::Post.new(FILES + '/t_user.ods', 1)
12
- post.exec(DB)
9
+ param = Condition::Param.new(FILES + '/t_user.ods')
10
+ param.pre(DB)
11
+ param = Condition::Param.new(FILES + '/t_user.ods', 1)
12
+ param.post(DB)
13
+ end
14
+
15
+ it 'pre and params' do
16
+ param = Condition::Param.new(FILES + '/t_user.ods')
17
+ param.pre(DB)
18
+
19
+ param = Condition::Param.new(FILES + '/t_user.ods', 2)
20
+ ds = DB[:t_user].prepare(:insert, :insert_with_name, {user_id: :$user_id, user_name: :$user_name})
21
+ ds.call(param.get_one('ins'))
22
+
23
+ list = DB["SELECT * FROM t_user"].all
24
+ param.check('list', list)
13
25
  end
14
26
  end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aoyagikouhei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-09 00:00:00.000000000 Z
11
+ date: 2013-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,10 +108,8 @@ files:
108
108
  - Rakefile
109
109
  - condition.gemspec
110
110
  - lib/condition.rb
111
- - lib/condition/post.rb
112
- - lib/condition/pre.rb
113
- - lib/condition/reader.rb
114
- - lib/condition/table.rb
111
+ - lib/condition/param.rb
112
+ - lib/condition/param_item.rb
115
113
  - lib/condition/version.rb
116
114
  - spec/condition_spec.rb
117
115
  - spec/files/t_user.ods
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Condition
4
- class Post
5
- include Condition::Reader;
6
-
7
- def initialize(path, sheet_index=0)
8
- tables = read_sheet(path, sheet_index)
9
- @tables = []
10
- tables.each do |rows|
11
- @tables << Condition::Table.new(rows)
12
- end
13
- end
14
-
15
- def exec(db)
16
- @tables.each do |table|
17
- list = table.all(db)
18
- list.each do |line|
19
- table.check_line(line)
20
- end
21
- end
22
- end
23
- end
24
- end
data/lib/condition/pre.rb DELETED
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Condition
4
- class Pre
5
- include Condition::Reader;
6
-
7
- def initialize(path, sheet_index=0)
8
- tables = read_sheet(path, sheet_index)
9
- @tables = []
10
- tables.each do |rows|
11
- @tables << Condition::Table.new(rows)
12
- end
13
- end
14
-
15
- def exec(db)
16
- @tables.each do |table|
17
- table.delete(db)
18
- table.insert(db)
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- require 'roo'
3
-
4
- module Condition
5
- module Reader
6
- def read_sheet(path, sheet_index)
7
- ss = Roo::Spreadsheet.open(path)
8
- ss.default_sheet = ss.sheets[sheet_index]
9
- row_index = 1
10
- res = []
11
- while true
12
- break if nil == ss.cell(row_index, 1)
13
- table = []
14
- while true
15
- row = read_row(ss, row_index)
16
- row_index += 1
17
- break if 0 == row.size
18
- table << row
19
- end
20
- res << table
21
- end
22
- res
23
- end
24
-
25
- def read_row(ss, row_index)
26
- column_index = 1
27
- result = []
28
- while true
29
- value = ss.cell(row_index, column_index)
30
- return result if nil == value
31
- result << value
32
- column_index += 1
33
- end
34
- end
35
- end
36
- end