anodator 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -1
- data/VERSION +1 -1
- data/lib/anodator/rule.rb +3 -0
- data/lib/anodator/utils.rb +10 -3
- data/lib/anodator/validator/numeric_validator.rb +3 -1
- data/spec/anodator/rule_spec.rb +77 -0
- data/spec/anodator/utils_spec.rb +48 -0
- data/spec/anodator/validator/numeric_validator_spec.rb +70 -0
- metadata +22 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -7,7 +7,7 @@ GEM
|
|
|
7
7
|
bundler (~> 1.0)
|
|
8
8
|
git (>= 1.2.5)
|
|
9
9
|
rake
|
|
10
|
-
rake (0.
|
|
10
|
+
rake (0.8.7)
|
|
11
11
|
rcov (0.9.9)
|
|
12
12
|
rspec (2.3.0)
|
|
13
13
|
rspec-core (~> 2.3.0)
|
|
@@ -24,5 +24,6 @@ PLATFORMS
|
|
|
24
24
|
DEPENDENCIES
|
|
25
25
|
bundler (~> 1.0.0)
|
|
26
26
|
jeweler (~> 1.6.4)
|
|
27
|
+
rake (= 0.8.7)
|
|
27
28
|
rcov
|
|
28
29
|
rspec (~> 2.3.0)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.3
|
data/lib/anodator/rule.rb
CHANGED
|
@@ -75,6 +75,9 @@ module Anodator
|
|
|
75
75
|
unless ERROR_LEVELS.values.include?(@level)
|
|
76
76
|
raise ArgumentError.new("level must be #{ERROR_LEVEL_NAMES.join(", ")}.")
|
|
77
77
|
end
|
|
78
|
+
if @prerequisite.is_a? Array
|
|
79
|
+
@prerequisite = Validator::ComplexValidator.new(:validators => @prerequisite)
|
|
80
|
+
end
|
|
78
81
|
end
|
|
79
82
|
|
|
80
83
|
# check values depend on prerequisite and validator
|
data/lib/anodator/utils.rb
CHANGED
|
@@ -46,7 +46,7 @@ module Anodator
|
|
|
46
46
|
# - target_values(for one error)
|
|
47
47
|
# - error_message(for one error)
|
|
48
48
|
# - error_level(for one error)
|
|
49
|
-
# - error_count(for one
|
|
49
|
+
# - error_count(for one data)
|
|
50
50
|
# - warning_count(for one data)
|
|
51
51
|
# - error_and_warning_count(for one data)
|
|
52
52
|
# Arguments:
|
|
@@ -181,7 +181,7 @@ module Anodator
|
|
|
181
181
|
# - rule description(string)
|
|
182
182
|
# - target expression(column identification or column name)
|
|
183
183
|
# - validator identification
|
|
184
|
-
# - prerequisite validator identification(allow blank)
|
|
184
|
+
# - prerequisite validator identification(allow blank and multiple validator identification)
|
|
185
185
|
# - error level(ERROR or WARNING)
|
|
186
186
|
# - error message holder(string)
|
|
187
187
|
# Return:
|
|
@@ -202,7 +202,14 @@ module Anodator
|
|
|
202
202
|
description = row[1]
|
|
203
203
|
target_expression = row[2].split(",")
|
|
204
204
|
validator = validators[row[3]]
|
|
205
|
-
|
|
205
|
+
if !row[4].nil? && row[4].include?(",")
|
|
206
|
+
prerequisite = row[4].split(",").map do |validator_id|
|
|
207
|
+
raise "Unknown validator identifier '#{validator_id}'" if validators[validator_id].nil?
|
|
208
|
+
next validators[validator_id]
|
|
209
|
+
end
|
|
210
|
+
else
|
|
211
|
+
prerequisite = validators[row[4]]
|
|
212
|
+
end
|
|
206
213
|
if validator.nil?
|
|
207
214
|
raise "Unknown validator identifier '#{row[3]}'"
|
|
208
215
|
end
|
|
@@ -5,7 +5,7 @@ module Anodator
|
|
|
5
5
|
module Validator
|
|
6
6
|
class NumericValidator < Base
|
|
7
7
|
valid_option_keys :only_integer, :greater_than, :greater_than_or_equal_to
|
|
8
|
-
valid_option_keys :less_than, :less_than_or_equal_to, :equal_to
|
|
8
|
+
valid_option_keys :less_than, :less_than_or_equal_to, :equal_to, :not_equal_to
|
|
9
9
|
default_options :only_integer => false
|
|
10
10
|
|
|
11
11
|
def validate
|
|
@@ -36,6 +36,8 @@ module Anodator
|
|
|
36
36
|
return false unless value <= BigDecimal.new(configuration.to_s)
|
|
37
37
|
when :equal_to
|
|
38
38
|
return false unless value == BigDecimal.new(configuration.to_s)
|
|
39
|
+
when :not_equal_to
|
|
40
|
+
return false unless value != BigDecimal.new(configuration.to_s)
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
|
data/spec/anodator/rule_spec.rb
CHANGED
|
@@ -115,6 +115,27 @@ describe Rule, "#new" do
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
|
+
|
|
119
|
+
context "with multiple prerequisite" do
|
|
120
|
+
before(:each) do
|
|
121
|
+
@new_proc = lambda {
|
|
122
|
+
v1 = Validator::PresenceValidator.new("1")
|
|
123
|
+
v2 = Validator::PresenceValidator.new("2")
|
|
124
|
+
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
|
125
|
+
@validator = Validator::ComplexValidator.new(:validators => [v1, v2])
|
|
126
|
+
@prerequisites = [
|
|
127
|
+
Validator::BlankValidator.new("3"),
|
|
128
|
+
Validator::BlankValidator.new("4")
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
Rule.new(["1", "2"], @message, @validator, @prerequisites, Rule::ERROR_LEVELS[:warning])
|
|
132
|
+
}
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should not raise Error" do
|
|
136
|
+
@new_proc.should_not raise_error
|
|
137
|
+
end
|
|
138
|
+
end
|
|
118
139
|
end
|
|
119
140
|
|
|
120
141
|
describe Rule, "#check" do
|
|
@@ -166,6 +187,62 @@ describe Rule, "#check" do
|
|
|
166
187
|
|
|
167
188
|
it { @rule.check.should be_nil }
|
|
168
189
|
end
|
|
190
|
+
|
|
191
|
+
context "with complex prerequisite" do
|
|
192
|
+
before(:each) do
|
|
193
|
+
@input_spec = InputSpec.new([
|
|
194
|
+
{ :number => "1", :name => "item_1" },
|
|
195
|
+
{ :number => "2", :name => "item_2" },
|
|
196
|
+
{ :number => "3", :name => "item_3" },
|
|
197
|
+
{ :number => "4", :name => "item_4" },
|
|
198
|
+
])
|
|
199
|
+
v1 = Validator::PresenceValidator.new("1")
|
|
200
|
+
v2 = Validator::PresenceValidator.new("2")
|
|
201
|
+
@message = Message.new("'[[1::name]]' and '[[2::name]]' cannot be blank")
|
|
202
|
+
@validator = Validator::ComplexValidator.new(:validators => [v1, v2], :logic => Validator::ComplexValidator::LOGIC_AND)
|
|
203
|
+
@prerequisites = [
|
|
204
|
+
Validator::BlankValidator.new("3"),
|
|
205
|
+
Validator::BlankValidator.new("4")
|
|
206
|
+
]
|
|
207
|
+
@rule = Rule.new(["item_1", "2"], @message, @validator, @prerequisites)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
context "when prerequisites matches and invalid" do
|
|
211
|
+
before(:each) do
|
|
212
|
+
@input_spec.source = ["1", "", "", ""]
|
|
213
|
+
Validator::Base.values = @input_spec
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it { @rule.check.should be_a CheckResult }
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
context "when prerequisites matches and valid" do
|
|
220
|
+
before(:each) do
|
|
221
|
+
@input_spec.source = ["1", "2", "", ""]
|
|
222
|
+
Validator::Base.values = @input_spec
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it { @rule.check.should be_nil }
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
context "when prerequisites not matches and valid" do
|
|
229
|
+
before(:each) do
|
|
230
|
+
@input_spec.source = ["1", "2", "", "4"]
|
|
231
|
+
Validator::Base.values = @input_spec
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it { @rule.check.should be_nil }
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
context "when prerequisites not matches and invalid" do
|
|
238
|
+
before(:each) do
|
|
239
|
+
@input_spec.source = ["1", "2", "", "4"]
|
|
240
|
+
Validator::Base.values = @input_spec
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it { @rule.check.should be_nil }
|
|
244
|
+
end
|
|
245
|
+
end
|
|
169
246
|
end
|
|
170
247
|
|
|
171
248
|
describe Rule, ".add_error_level" do
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "tempfile"
|
|
3
|
+
|
|
4
|
+
# Anodator::Utils
|
|
5
|
+
require "anodator"
|
|
6
|
+
require "anodator/utils"
|
|
7
|
+
|
|
8
|
+
include Anodator
|
|
9
|
+
|
|
10
|
+
describe Utils, ".load_input_spec_from_csv_file" do
|
|
11
|
+
context "read valid file" do
|
|
12
|
+
before(:each) do
|
|
13
|
+
@file = Tempfile.new(["input_spec", ".csv"])
|
|
14
|
+
|
|
15
|
+
# Header
|
|
16
|
+
@file.puts(["id", "name", "type"].join(","))
|
|
17
|
+
# values
|
|
18
|
+
@values = [
|
|
19
|
+
{ :id => "1", :name => "Name", :type => "STRING" },
|
|
20
|
+
{ :id => "2", :name => "Age", :type => "NUMERIC" },
|
|
21
|
+
{ :id => "3", :name => "Birtyday", :type => "DATE" },
|
|
22
|
+
{ :id => "4", :name => "Sex", :type => "NUMERIC" },
|
|
23
|
+
{ :id => "5", :name => "Email", :type => "STRING" },
|
|
24
|
+
]
|
|
25
|
+
@values.each do |v|
|
|
26
|
+
@file.puts("#{v[:id]},#{v[:name]},#{v[:type]}")
|
|
27
|
+
end
|
|
28
|
+
@file.close
|
|
29
|
+
|
|
30
|
+
@proc = lambda {
|
|
31
|
+
Utils.load_input_spec_from_csv_file(@file.path)
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
after(:each) do
|
|
36
|
+
@file.unlink
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it { @proc.should_not raise_error }
|
|
40
|
+
|
|
41
|
+
it "should have all items" do
|
|
42
|
+
input_spec = @proc.call
|
|
43
|
+
@values.each do |value|
|
|
44
|
+
input_spec.spec_item_by_expression(value[:id]).should_not be_nil
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -125,6 +125,22 @@ describe NumericValidator, ".new" do
|
|
|
125
125
|
@new_proc.call.options[:equal_to].should == 10
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
|
+
|
|
129
|
+
context "with target expression and :not_equal_to" do
|
|
130
|
+
before(:each) do
|
|
131
|
+
@new_proc = lambda {
|
|
132
|
+
NumericValidator.new("1", :not_equal_to => 10)
|
|
133
|
+
}
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should not raise error" do
|
|
137
|
+
@new_proc.should_not raise_error
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it ":not_equal_to option must be exists" do
|
|
141
|
+
@new_proc.call.options[:not_equal_to].should == 10
|
|
142
|
+
end
|
|
143
|
+
end
|
|
128
144
|
end
|
|
129
145
|
|
|
130
146
|
describe NumericValidator, "#valid?" do
|
|
@@ -465,4 +481,58 @@ describe NumericValidator, "#valid?" do
|
|
|
465
481
|
it { @validator.should_not be_valid }
|
|
466
482
|
end
|
|
467
483
|
end
|
|
484
|
+
|
|
485
|
+
context "with target expression and :not_equal_to" do
|
|
486
|
+
before(:each) do
|
|
487
|
+
@validator = NumericValidator.new("1", :not_equal_to => 10)
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
context "values for valid maximum value" do
|
|
491
|
+
before(:each) do
|
|
492
|
+
Base.values = { "1" => "9" }
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
it { @validator.should be_valid }
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
context "values for valid maximum floating point value" do
|
|
499
|
+
before(:each) do
|
|
500
|
+
Base.values = { "1" => "9.9999999" }
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
it { @validator.should be_valid }
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
context "values for invalid equal value" do
|
|
507
|
+
before(:each) do
|
|
508
|
+
Base.values = { "1" => "10" }
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
it { @validator.should_not be_valid }
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
context "values for invalid equal floating point value" do
|
|
515
|
+
before(:each) do
|
|
516
|
+
Base.values = { "1" => "10.0" }
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
it { @validator.should_not be_valid }
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
context "values for valid minimum value" do
|
|
523
|
+
before(:each) do
|
|
524
|
+
Base.values = { "1" => "11" }
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
it { @validator.should be_valid }
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
context "values for valid minimum floating potin value" do
|
|
531
|
+
before(:each) do
|
|
532
|
+
Base.values = { "1" => "10.0000001" }
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
it { @validator.should be_valid }
|
|
536
|
+
end
|
|
537
|
+
end
|
|
468
538
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: anodator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
9
|
+
- 3
|
|
10
10
|
segments_generated: true
|
|
11
|
-
version: 0.0.
|
|
11
|
+
version: 0.0.3
|
|
12
12
|
platform: ruby
|
|
13
13
|
authors:
|
|
14
14
|
- Tetsuhisa MAKINO
|
|
@@ -16,7 +16,7 @@ autorequire:
|
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
18
|
|
|
19
|
-
date: 2011-10-
|
|
19
|
+
date: 2011-10-21 00:00:00 +09:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies:
|
|
22
22
|
- !ruby/object:Gem::Dependency
|
|
@@ -85,6 +85,23 @@ dependencies:
|
|
|
85
85
|
version: "0"
|
|
86
86
|
requirement: *id004
|
|
87
87
|
type: :development
|
|
88
|
+
- !ruby/object:Gem::Dependency
|
|
89
|
+
prerelease: false
|
|
90
|
+
name: rake
|
|
91
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
|
92
|
+
none: false
|
|
93
|
+
requirements:
|
|
94
|
+
- - "="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
hash: 49
|
|
97
|
+
segments:
|
|
98
|
+
- 0
|
|
99
|
+
- 8
|
|
100
|
+
- 7
|
|
101
|
+
segments_generated: true
|
|
102
|
+
version: 0.8.7
|
|
103
|
+
requirement: *id005
|
|
104
|
+
type: :development
|
|
88
105
|
description: anodator is Anonymous Data Validator.
|
|
89
106
|
email: tim.makino at gmail.com
|
|
90
107
|
executables: []
|
|
@@ -136,6 +153,7 @@ files:
|
|
|
136
153
|
- spec/anodator/output_spec_spec.rb
|
|
137
154
|
- spec/anodator/rule_set_spec.rb
|
|
138
155
|
- spec/anodator/rule_spec.rb
|
|
156
|
+
- spec/anodator/utils_spec.rb
|
|
139
157
|
- spec/anodator/validator/base_spec.rb
|
|
140
158
|
- spec/anodator/validator/blank_validator_spec.rb
|
|
141
159
|
- spec/anodator/validator/complex_validator_spec.rb
|