ruva 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +1,57 @@
1
- def create_is_spec identifier, comparable
2
- spec = ExpressionLeafSpec.new(identifier.value, comparable.value)
3
- spec.set_validator { |value, *args|
4
- @comparable == value
5
- }
6
- spec.set_reporting { |satisfied, value, *args|
7
- comparable_string = @comparable.to_s
8
- create_report_string "is #{comparable_string}", "is not #{comparable_string}", satisfied, value
9
- }
10
- spec
11
- end
1
+ module Ruva
2
+ module Expression
3
+ def self.create_is_spec identifier, comparable
4
+ spec = ExpressionLeafSpec.new(identifier.value, comparable.value)
5
+ spec.set_validator { |value, *args|
6
+ @comparable == value
7
+ }
8
+ spec.set_reporting { |satisfied, value, *args|
9
+ comparable_string = @comparable.to_s
10
+ create_report_string "is #{comparable_string}", "is not #{comparable_string}", satisfied, value
11
+ }
12
+ spec
13
+ end
12
14
 
13
- module Is
14
- def value
15
- create_is_spec identifier, comparable
16
- end
17
- end
15
+ module Is
16
+ def value
17
+ Ruva::Expression.create_is_spec identifier, comparable
18
+ end
19
+ end
18
20
 
19
- module ManyIs
20
- def value
21
- spec = create_spec
22
- comparables.value.reverse.each do |comparable|
23
- new_spec = create_is_spec identifier, comparable
24
- spec.append(new_spec)
21
+ module ManyIs
22
+ def value
23
+ spec = create_spec
24
+ comparables.value.reverse.each do |comparable|
25
+ new_spec = Ruva::Expression.create_is_spec identifier, comparable
26
+ spec.append(new_spec)
27
+ end
28
+ spec
29
+ end
25
30
  end
26
- spec
27
- end
28
- end
29
31
 
30
- module OrIs include ManyIs
31
- def create_spec
32
- OrSpec.new
33
- end
34
- end
32
+ module OrIs include ManyIs
33
+ def create_spec
34
+ Ruva::Specification::OrSpec.new
35
+ end
36
+ end
35
37
 
36
- module IsBetween
37
- def value
38
- comparables = [from.value, to.value]
39
- spec = ExpressionLeafSpec.new(identifier.value, comparables)
40
- spec.set_validator { |value, *args|
41
- if value
42
- value.between? @comparable[0], @comparable[1]
43
- else
44
- false
38
+ module IsBetween
39
+ def value
40
+ comparables = [from.value, to.value]
41
+ spec = ExpressionLeafSpec.new(identifier.value, comparables)
42
+ spec.set_validator { |value, *args|
43
+ if value
44
+ value.between? @comparable[0], @comparable[1]
45
+ else
46
+ false
47
+ end
48
+ }
49
+ spec.set_reporting { |satisfied, value, *args|
50
+ comparable_string = "#{@comparable[0]} and #{@comparable[1]}"
51
+ create_report_string "is between #{comparable_string}", "is not between #{comparable_string}", satisfied, value
52
+ }
53
+ spec
45
54
  end
46
- }
47
- spec.set_reporting { |satisfied, value, *args|
48
- comparable_string = "#{@comparable[0]} and #{@comparable[1]}"
49
- create_report_string "is between #{comparable_string}", "is not between #{comparable_string}", satisfied, value
50
- }
51
- spec
55
+ end
52
56
  end
53
57
  end
@@ -1,42 +1,46 @@
1
- def create_matches_spec identifier, comparable
2
- comparable = comparable.value
3
- regex = comparable.is_a?(Regexp) ? comparable : Regexp.new(comparable)
4
- spec = ExpressionLeafSpec.new(identifier.value, regex)
5
- spec.set_validator { |value, *args|
6
- (@comparable =~ value) != nil
7
- }
8
- spec.set_reporting { |satisfied, value, *args|
9
- comparable_string = "/#{@comparable.source}/"
10
- create_report_string "matches #{comparable_string}", "does not match #{comparable_string}", satisfied, value
11
- }
12
- spec
13
- end
1
+ module Ruva
2
+ module Expression
3
+ def self.create_matches_spec identifier, comparable
4
+ comparable = comparable.value
5
+ regex = comparable.is_a?(Regexp) ? comparable : Regexp.new(comparable)
6
+ spec = ExpressionLeafSpec.new(identifier.value, regex)
7
+ spec.set_validator { |value, *args|
8
+ (@comparable =~ value) != nil
9
+ }
10
+ spec.set_reporting { |satisfied, value, *args|
11
+ comparable_string = "/#{@comparable.source}/"
12
+ create_report_string "matches #{comparable_string}", "does not match #{comparable_string}", satisfied, value
13
+ }
14
+ spec
15
+ end
14
16
 
15
- module Matches
16
- def value
17
- create_matches_spec identifier, comparable
18
- end
19
- end
17
+ module Matches
18
+ def value
19
+ Ruva::Expression.create_matches_spec identifier, comparable
20
+ end
21
+ end
20
22
 
21
- module ManyMatches
22
- def value
23
- spec = create_spec
24
- comparables.value.reverse.each do |comparable|
25
- new_spec = create_matches_spec identifier, comparable
26
- spec.append(new_spec)
23
+ module ManyMatches
24
+ def value
25
+ spec = create_spec
26
+ comparables.value.reverse.each do |comparable|
27
+ new_spec = Ruva::Expression.create_matches_spec identifier, comparable
28
+ spec.append(new_spec)
29
+ end
30
+ spec
31
+ end
27
32
  end
28
- spec
29
- end
30
- end
31
33
 
32
- module AndMatches include ManyMatches
33
- def create_spec
34
- AndSpec.new
35
- end
36
- end
34
+ module AndMatches include ManyMatches
35
+ def create_spec
36
+ AndSpec.new
37
+ end
38
+ end
37
39
 
38
- module OrMatches include ManyMatches
39
- def create_spec
40
- OrSpec.new
40
+ module OrMatches include ManyMatches
41
+ def create_spec
42
+ OrSpec.new
43
+ end
44
+ end
41
45
  end
42
46
  end
@@ -1,51 +1,51 @@
1
- grammar RuvaExpression
2
-
1
+ grammar Ruva::Expression::RuvaExpression
2
+
3
3
  rule root
4
- (identifier matches comparables:(and_comparables)) <AndMatches>
4
+ (identifier matches comparables:(and_comparables)) <Ruva::Expression::AndMatches>
5
5
  |
6
- (identifier matches comparables:(or_comparables)) <OrMatches>
6
+ (identifier matches comparables:(or_comparables)) <Ruva::Expression::OrMatches>
7
7
  |
8
- (identifier matches comparable) <Matches>
8
+ (identifier matches comparable) <Ruva::Expression::Matches>
9
9
  |
10
- (identifier is between from:(comparable) and to:(comparable)) <IsBetween>
10
+ (identifier is between from:(comparable) and to:(comparable)) <Ruva::Expression::IsBetween>
11
11
  |
12
- (identifier is greater than or equal to comparable) <GreaterOrEqual>
12
+ (identifier is greater than or equal to comparable) <Ruva::Expression::GreaterOrEqual>
13
13
  |
14
- (identifier is less than or equal to comparable) <LessOrEqual>
14
+ (identifier is less than or equal to comparable) <Ruva::Expression::LessOrEqual>
15
15
  |
16
- (identifier is greater than comparable) <Greater>
16
+ (identifier is greater than comparable) <Ruva::Expression::Greater>
17
17
  |
18
- (identifier is less than comparable) <Less>
18
+ (identifier is less than comparable) <Ruva::Expression::Less>
19
19
  |
20
- (identifier is comparable or more) <GreaterOrEqual>
20
+ (identifier is comparable or more) <Ruva::Expression::GreaterOrEqual>
21
21
  |
22
- (identifier is comparable or less) <LessOrEqual>
22
+ (identifier is comparable or less) <Ruva::Expression::LessOrEqual>
23
23
  |
24
- (identifier is comparables:(or_comparables)) <OrIs>
24
+ (identifier is comparables:(or_comparables)) <Ruva::Expression::OrIs>
25
25
  |
26
- (identifier is comparable) <Is>
26
+ (identifier is comparable) <Ruva::Expression::Is>
27
27
  end
28
28
 
29
29
  rule matches
30
30
  'matches' space
31
31
  end
32
-
32
+
33
33
  rule is
34
34
  'is' space
35
35
  end
36
-
36
+
37
37
  rule between
38
38
  'between' space
39
39
  end
40
-
40
+
41
41
  rule greater
42
42
  'greater' space
43
43
  end
44
-
44
+
45
45
  rule less
46
46
  'less' space
47
47
  end
48
-
48
+
49
49
  rule more
50
50
  'more' space
51
51
  end
@@ -53,68 +53,68 @@ grammar RuvaExpression
53
53
  rule than
54
54
  'than' space
55
55
  end
56
-
56
+
57
57
  rule equal
58
58
  'equal' space
59
59
  end
60
-
60
+
61
61
  rule to
62
62
  'to' space
63
63
  end
64
-
64
+
65
65
  rule and
66
66
  'and' space
67
67
  end
68
-
68
+
69
69
  rule or
70
70
  'or' space
71
- end
72
-
71
+ end
72
+
73
73
  rule identifier
74
- ([a-zA-Z0-9_.\[\]]+ space) <Identifier>
74
+ ([a-zA-Z0-9_.\[\]]+ space) <Ruva::Expression::Identifier>
75
75
  end
76
76
 
77
77
  rule comparable
78
78
  (number_comparable | date_comparable | regex_comparable | text_comparable)
79
79
  end
80
-
80
+
81
81
  rule last_comparable
82
- (comparable '') <LastComparable>
82
+ (comparable '') <Ruva::Expression::LastComparable>
83
83
  end
84
84
 
85
85
  rule number_comparable
86
86
  (int_comparable | float_comparable)
87
87
  end
88
-
88
+
89
89
  rule int_comparable
90
- ([0-9]+ space) <IntComparable>
90
+ ([0-9]+ space) <Ruva::Expression::IntComparable>
91
91
  end
92
-
92
+
93
93
  rule float_comparable
94
- ([0-9]* '.' [0-9]+ space) <FloatComparable>
94
+ ([0-9]* '.' [0-9]+ space) <Ruva::Expression::FloatComparable>
95
95
  end
96
-
96
+
97
97
  rule date_comparable
98
- ([0-9]2*2 '.' [0-9]2*2 '.' [0-9]4*4 space) <DateComparable>
98
+ ([0-9]2*2 '.' [0-9]2*2 '.' [0-9]4*4 space) <Ruva::Expression::DateComparable>
99
99
  end
100
-
100
+
101
101
  rule regex_comparable
102
- ('/' regex:((!'/'!'\\' .) | '\\/' | '\\\\')* '/' space) <RegexComparable>
102
+ ('/' regex:((!'/'!'\\' .) | '\\/' | '\\\\')* '/' space) <Ruva::Expression::RegexComparable>
103
103
  end
104
-
104
+
105
105
  rule text_comparable
106
- ([^ ]+ space) <TextComparable>
106
+ ([^ ]+ space) <Ruva::Expression::TextComparable>
107
107
  end
108
108
 
109
109
  rule and_comparables
110
- (comparable and subresult:(and_comparables | last_comparable)) <Comparables>
110
+ (comparable and subresult:(and_comparables | last_comparable)) <Ruva::Expression::Comparables>
111
111
  end
112
112
 
113
113
  rule or_comparables
114
- (comparable or subresult:(or_comparables | last_comparable)) <Comparables>
114
+ (comparable or subresult:(or_comparables | last_comparable)) <Ruva::Expression::Comparables>
115
115
  end
116
-
116
+
117
117
  rule space
118
118
  [ \t]+ | /$/
119
119
  end
120
- end
120
+ end
@@ -1,110 +1,93 @@
1
- class Spec
2
- def initialize
3
- @specs = Array.new
4
- end
5
-
6
- def append spec
7
- @specs << spec
8
- spec
9
- end
10
-
11
- def create_subreport spec, *args
12
- if spec.is_a? Spec
13
- spec.evaluate *args
14
- else
15
- result = spec.evaluate *args
16
- message = spec.report result, *args
17
- SpecReport.new result, message
18
- end
19
- end
20
-
21
- def report satisfied, *args
22
- # report = SpecReport.new false, name
23
- # @specs.each do |spec|
24
- # subreport = create_subreport spec, *args
25
- # report.add_subreport subreport
26
- # if condition_change? subreport.satisfied
27
- # passed = !initial_condition
28
- # end
29
- # end
30
- # report.satisfied = passed
31
- # report
32
- end
1
+ module Ruva
2
+ module Specification
3
+ class Spec
4
+ def initialize
5
+ @specs = Array.new
6
+ end
33
7
 
34
- def evaluate *args
35
- passed = initial_condition
36
- @specs.each do |spec|
37
- result = spec.evaluate *args
38
- if condition_change? result
39
- passed = !initial_condition
8
+ def append spec
9
+ @specs << spec
10
+ spec
40
11
  end
41
- end
42
- passed
43
- end
44
- end
45
12
 
46
- class AndSpec < Spec
47
- def initial_condition() return true end
48
- def name() "all" end
49
- def condition_change?(satisfied) !satisfied end
50
- end
13
+ # def create_subreport spec, *args
14
+ # if spec.is_a? Spec
15
+ # spec.evaluate *args
16
+ # else
17
+ # result = spec.evaluate *args
18
+ # message = spec.report result, *args
19
+ # SpecReport.new result, message
20
+ # end
21
+ # end
51
22
 
52
- class OrSpec < Spec
53
- def initial_condition() return false end
54
- def name() "any" end
55
- def condition_change?(satisfied) satisfied end
56
- end
23
+ # def report satisfied, *args
24
+ # report = SpecReport.new false, name
25
+ # @specs.each do |spec|
26
+ # subreport = create_subreport spec, *args
27
+ # report.add_subreport subreport
28
+ # if condition_change? subreport.satisfied
29
+ # passed = !initial_condition
30
+ # end
31
+ # end
32
+ # report.satisfied = passed
33
+ # report
34
+ # end
57
35
 
58
- class NotSpec < Spec
59
- def initial_condition() return true end
60
- def name() "none" end
61
- def condition_change?(satisfied) satisfied end
62
- end
36
+ def evaluate value
37
+ passed = initial_condition
38
+ @specs.each do |spec|
39
+ result = spec.evaluate value
40
+ if condition_change? result
41
+ passed = !initial_condition
42
+ end
43
+ end
44
+ passed
45
+ end
46
+ end
63
47
 
64
- class LeafSpec
65
- def initialize name, args
66
- @name = name
67
- @comparable = args
68
- end
69
-
70
- def set_validator &block
71
- @validator = block
72
- end
73
-
74
- def set_reporting &block
75
- @reporting = block
76
- end
77
-
78
- def evaluate *args
79
- instance_exec(get_value(*args), *args, &@validator)
80
- end
81
-
82
- def report satisfied, *args
83
- instance_exec(satisfied, get_value(*args), *args, &@reporting)
84
- end
85
- end
48
+ class AndSpec < Spec
49
+ def initial_condition() return true end
50
+ def name() "all" end
51
+ def condition_change?(satisfied) !satisfied end
52
+ end
86
53
 
87
- class SpecReport
88
-
89
- attr_accessor :satisfied, :name, :input
90
-
91
- def initialize satisfied, message
92
- @satisfied = satisfied
93
- @message = message
94
- @subreports = Array.new
95
- end
96
-
97
- def add_subreport subreport
98
- @subreports << subreport
99
- end
100
-
101
- def to_s s = ''
102
- met = @satisfied ? "[+] " : "[-] "
103
- output = s + met + @message
104
- output += "\n"
105
- @subreports.each do |subreport|
106
- output += subreport.to_s(s + ' ')
54
+ class OrSpec < Spec
55
+ def initial_condition() return false end
56
+ def name() "any" end
57
+ def condition_change?(satisfied) satisfied end
58
+ end
59
+
60
+ class NotSpec < Spec
61
+ def initial_condition() return true end
62
+ def name() "none" end
63
+ def condition_change?(satisfied) satisfied end
107
64
  end
108
- output
65
+
66
+
67
+
68
+ # class SpecReport
69
+
70
+ # attr_accessor :satisfied, :name, :input
71
+
72
+ # def initialize satisfied, message
73
+ # @satisfied = satisfied
74
+ # @message = message
75
+ # @subreports = Array.new
76
+ # end
77
+
78
+ # def add_subreport subreport
79
+ # @subreports << subreport
80
+ # end
81
+
82
+ # def to_s s = ''
83
+ # met = @satisfied ? "[+] " : "[-] "
84
+ # output = s + met + @message
85
+ # output += "\n"
86
+ # @subreports.each do |subreport|
87
+ # output += subreport.to_s(s + ' ')
88
+ # end
89
+ # output
90
+ # end
91
+ # end
109
92
  end
110
93
  end