Class: Wongi::Engine::DSL::Rule
- Inherits:
-
Object
- Object
- Wongi::Engine::DSL::Rule
show all
- Defined in:
- lib/wongi-engine/dsl/rule.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name) ⇒ Rule
Returns a new instance of Rule.
28
29
30
31
32
|
# File 'lib/wongi-engine/dsl/rule.rb', line 28
def initialize(name)
@name = name
@current_section = nil
Rule.sections.each { |section| acceptors[section] ||= [] }
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/wongi-engine/dsl/rule.rb', line 4
def name
@name
end
|
Class Method Details
.section(s, *aliases) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/wongi-engine/dsl/rule.rb', line 7
def section(s, *aliases)
return if sections.include?(s)
sections << s
define_method s do |&d|
@current_section = s
section = DSL.sections[s].new
section.rule = self
section.instance_eval(&d)
end
aliases.each { |a| alias_method a, s }
end
|
.sections ⇒ Object
20
21
22
|
# File 'lib/wongi-engine/dsl/rule.rb', line 20
def sections
@sections ||= []
end
|
Instance Method Details
#accept(stuff) ⇒ Object
72
73
74
|
# File 'lib/wongi-engine/dsl/rule.rb', line 72
def accept(stuff)
acceptors[@current_section] << stuff
end
|
#acceptors ⇒ Object
34
35
36
|
# File 'lib/wongi-engine/dsl/rule.rb', line 34
def acceptors
@acceptors ||= {}
end
|
#actions ⇒ Object
46
47
48
|
# File 'lib/wongi-engine/dsl/rule.rb', line 46
def actions
acceptors[:make] ||= []
end
|
#actions=(a) ⇒ Object
50
51
52
|
# File 'lib/wongi-engine/dsl/rule.rb', line 50
def actions=(a)
acceptors[:make] = a
end
|
#conditions ⇒ Object
38
39
40
|
# File 'lib/wongi-engine/dsl/rule.rb', line 38
def conditions
acceptors[:forall] ||= []
end
|
#conditions=(c) ⇒ Object
42
43
44
|
# File 'lib/wongi-engine/dsl/rule.rb', line 42
def conditions=(c)
acceptors[:forall] = c
end
|
#import_into(rete) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/wongi-engine/dsl/rule.rb', line 54
def import_into(rete)
self.class.new(@name).tap do |copy|
copy.conditions = conditions
copy.actions = actions.map do |action|
if action.respond_to? :import_into
action.import_into(rete)
else
action
end
end
end
end
|
#install(rete) ⇒ Object
68
69
70
|
# File 'lib/wongi-engine/dsl/rule.rb', line 68
def install(rete)
rete.install_rule(self)
end
|