Class: Wongi::Engine::DSL::Rule

Inherits:
Object
  • Object
show all
Includes:
Generated
Defined in:
lib/wongi-engine/dsl/rule.rb

Direct Known Subclasses

NccSubrule, Query, VariantRule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generated

create_dsl_method

Constructor Details

#initialize(name) ⇒ Rule

Returns a new instance of Rule.



30
31
32
33
34
# File 'lib/wongi-engine/dsl/rule.rb', line 30

def initialize name
  @name = name
  @current_section = nil
  DSL::Rule.sections.each { |section| acceptors[section] ||= [] }
end

Instance Attribute Details

#nameObject (readonly)

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



10
11
12
13
14
15
16
17
18
19
# File 'lib/wongi-engine/dsl/rule.rb', line 10

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

.sectionsObject



21
22
23
# File 'lib/wongi-engine/dsl/rule.rb', line 21

def sections
  @sections ||= []
end

Instance Method Details

#acceptorsObject



36
37
38
# File 'lib/wongi-engine/dsl/rule.rb', line 36

def acceptors
  @acceptors ||= {}
end

#actionsObject



48
49
50
# File 'lib/wongi-engine/dsl/rule.rb', line 48

def actions
  acceptors[:make] ||= []
end

#actions=(a) ⇒ Object



52
53
54
# File 'lib/wongi-engine/dsl/rule.rb', line 52

def actions= a
  acceptors[:make] = a
end

#conditionsObject



40
41
42
# File 'lib/wongi-engine/dsl/rule.rb', line 40

def conditions
  acceptors[:forall] ||= []
end

#conditions=(c) ⇒ Object



44
45
46
# File 'lib/wongi-engine/dsl/rule.rb', line 44

def conditions= c
  acceptors[:forall] = c
end

#import_into(rete) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wongi-engine/dsl/rule.rb', line 56

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



70
71
72
# File 'lib/wongi-engine/dsl/rule.rb', line 70

def install( rete )
  rete.install_rule( self )
end