Class: Wongi::Engine::DSL::Action::StatementGenerator

Inherits:
BaseAction
  • Object
show all
Defined in:
lib/wongi-engine/dsl/action/statement_generator.rb

Instance Attribute Summary

Attributes inherited from BaseAction

#name, #production, #rete, #rule

Instance Method Summary collapse

Methods inherited from BaseAction

#overlay

Methods included from CoreExt

included

Constructor Details

#initialize(template) ⇒ StatementGenerator

Returns a new instance of StatementGenerator.



9
10
11
12
# File 'lib/wongi-engine/dsl/action/statement_generator.rb', line 9

def initialize(template)
  super()
  @template = template
end

Instance Method Details

#execute(token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wongi-engine/dsl/action/statement_generator.rb', line 14

def execute(token)
  # p execute: {token:}
  subject, predicate, object = template.resolve!(token)

  wme = WME.new(subject, predicate, object)
  wme = overlay.find(wme) || wme

  production.tracer.trace(action: self, wme: wme) if production.tracer

  if should_assert?(wme, token)
    overlay.assert(wme, generator: token)
  end
end