aristotle 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aristotle/command.rb +17 -5
- data/lib/aristotle/logic.rb +0 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7000dc8a548a5d2a5343d9dfd99e6820ff5fd97e
|
4
|
+
data.tar.gz: a1e9ae1f39ae50bd138ecb8046c0ab39eeea1121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d5ab3d22b63e0fbe495885c8934af0c8b8d38de71ac710dfacf6ce1d233203efc0b1c65cd3c682bb3151d728f7134138abd73026d169d99f857132c4c74b856
|
7
|
+
data.tar.gz: e4c1124a661d822dbfb02678abf039488fd1a7bb4c9aee00b7c972f7d32e08a9310a9a52227d9cad3341c3b3f6d8feff1522044ffffa717b3dddb3de2a22175b
|
data/lib/aristotle/command.rb
CHANGED
@@ -3,18 +3,30 @@ module Aristotle
|
|
3
3
|
attr_reader :action, :condition
|
4
4
|
|
5
5
|
def initialize(line, conditions, actions)
|
6
|
-
# TODO: make this properly work with regexps
|
7
6
|
@action, @condition = line.split(' if ', 2).map(&:strip)
|
8
7
|
|
9
8
|
raise 'Badly formatted line' if @action == '' || @condition == ''
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
conditions.each do |condition_regexp, condition_proc|
|
11
|
+
match_data = condition_regexp.match(@condition)
|
12
|
+
if match_data
|
13
|
+
@condition_proc = condition_proc
|
14
|
+
@condition_attributes = match_data.to_a[1..-1]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
actions.each do |action_regexp, action_proc|
|
19
|
+
match_data = action_regexp.match(@action)
|
20
|
+
if match_data
|
21
|
+
@action_proc = action_proc
|
22
|
+
@action_attributes = match_data.to_a[1..-1]
|
23
|
+
end
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
def do_action_with(object)
|
16
28
|
if @action_proc
|
17
|
-
@action_proc.call(object)
|
29
|
+
@action_proc.call(object, *@action_attributes)
|
18
30
|
else
|
19
31
|
raise "Action not found: #{@action}"
|
20
32
|
end
|
@@ -22,7 +34,7 @@ module Aristotle
|
|
22
34
|
|
23
35
|
def condition_passes_with?(object)
|
24
36
|
if @condition_proc
|
25
|
-
@condition_proc.call(object)
|
37
|
+
@condition_proc.call(object, *@condition_attributes)
|
26
38
|
else
|
27
39
|
raise "Condition not found: #{@condition}"
|
28
40
|
end
|
data/lib/aristotle/logic.rb
CHANGED
@@ -47,11 +47,7 @@ module Aristotle
|
|
47
47
|
raise "#{filename} is broken!" if command.nil?
|
48
48
|
|
49
49
|
@@commands[command] ||= []
|
50
|
-
# begin
|
51
50
|
@@commands[command] << Aristotle::Command.new(line.strip, @@conditions, @@actions)
|
52
|
-
# rescue => e
|
53
|
-
# raise e.message + ' in ' + filename
|
54
|
-
# end
|
55
51
|
else
|
56
52
|
command = line
|
57
53
|
end
|