aristotle 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08566772bb5f4c2458e5eff1058c23f87601805c
4
- data.tar.gz: 804ce18d078fc5ab280fce17d39dec1994f33dea
3
+ metadata.gz: 7000dc8a548a5d2a5343d9dfd99e6820ff5fd97e
4
+ data.tar.gz: a1e9ae1f39ae50bd138ecb8046c0ab39eeea1121
5
5
  SHA512:
6
- metadata.gz: c4199a7fd2511951eaf4ba159e6b8bceb86293e1d1d81676858064e3209d7eb492b2b7d99651f0905e0956edcf65996c77695c2d74d134c5e708681838a41492
7
- data.tar.gz: c2c2413a36d7d18b92b6aa9e659b55951e3c18a9b84fa8d268a505811e5b1bd5b304d2d075be9a4d3c5ccbc5937997b62a83999d161c328f4b72e7b707a90bc3
6
+ metadata.gz: 8d5ab3d22b63e0fbe495885c8934af0c8b8d38de71ac710dfacf6ce1d233203efc0b1c65cd3c682bb3151d728f7134138abd73026d169d99f857132c4c74b856
7
+ data.tar.gz: e4c1124a661d822dbfb02678abf039488fd1a7bb4c9aee00b7c972f7d32e08a9310a9a52227d9cad3341c3b3f6d8feff1522044ffffa717b3dddb3de2a22175b
@@ -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
- @condition_proc = conditions[Regexp.new(@condition)]
12
- @action_proc = actions[Regexp.new(@action)]
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aristotle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Andra