Class: Wongi::Engine::DSL::Action::SimpleCollector

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

Instance Attribute Summary

Attributes inherited from BaseAction

#name, #production, #rete, #rule

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAction

#overlay

Methods included from CoreExt

included

Constructor Details

#initialize(variable, name = nil) ⇒ SimpleCollector

Returns a new instance of SimpleCollector.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/wongi-engine/dsl/action/simple_collector.rb', line 8

def initialize(variable, name = nil)
  super()
  @variable = variable
  @name = name if name
  # (class << self; self; end).instance_eval do
  #        define_method method do
  #          collect variable
  #        end
  #    alias_method method, :default_collect
  #  end
end

Class Method Details

.collectorObject



4
5
6
# File 'lib/wongi-engine/dsl/action/simple_collector.rb', line 4

def self.collector
  Class.new self
end

Instance Method Details

#collect(var) ⇒ Object



32
33
34
# File 'lib/wongi-engine/dsl/action/simple_collector.rb', line 32

def collect(var)
  production.tokens.map { |token| token[var] }
end

#default_collectObject



20
21
22
# File 'lib/wongi-engine/dsl/action/simple_collector.rb', line 20

def default_collect
  collect @variable
end

#name=(n) ⇒ Object



24
25
26
# File 'lib/wongi-engine/dsl/action/simple_collector.rb', line 24

def name=(n)
  @name ||= n
end

#rete=(rete) ⇒ Object



28
29
30
# File 'lib/wongi-engine/dsl/action/simple_collector.rb', line 28

def rete=(rete)
  rete.add_collector self, name
end