Class: Wongi::Engine::GenericProductionRule
- Inherits:
-
Object
- Object
- Wongi::Engine::GenericProductionRule
- Includes:
- DSLExtensions
- Defined in:
- lib/wongi-engine/dsl/generic_production_rule.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #import_into(rete) ⇒ Object
-
#initialize(name) ⇒ GenericProductionRule
constructor
A new instance of GenericProductionRule.
Methods included from DSLExtensions
Constructor Details
#initialize(name) ⇒ GenericProductionRule
Returns a new instance of GenericProductionRule.
31 32 33 34 35 36 37 38 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 31 def initialize name @name = name @conditions = [] @actions = [] @current_section = nil @acceptors = {} GenericProductionRule.sections.each { |section| @acceptors[section] ||= [] } end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
5 6 7 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 5 def actions @actions end |
#conditions ⇒ Object
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 5 def conditions @conditions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 4 def name @name end |
Class Method Details
.section(s, *aliases) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 11 def section s, *aliases unless sections.include?(s) sections << s define_method s do |&d| @current_section = s instance_eval &d end aliases.each { |a| alias_method a, s } end end |
.sections ⇒ Object
22 23 24 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 22 def sections @sections ||= [] end |
Instance Method Details
#import_into(rete) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wongi-engine/dsl/generic_production_rule.rb', line 40 def import_into rete copy = self.class.new @name copy.conditions = @acceptors[:forall].map do |condition| if condition.respond_to? :import_into condition.import_into(rete) else condition end end copy.actions = @acceptors[:make].map do |action| if action.respond_to? :import_into action.import_into(rete) else action end end copy rescue Exception => e e1 = Exception.new "in rule #{name}: #{e}" e1.set_backtrace e.backtrace raise e1 end |