Class: Ruleby::Core::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/core/engine.rb

Overview

An action is a wrapper for a code block that will be executed if a rule is satisfied.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Action

Returns a new instance of Action.



28
29
30
31
32
# File 'lib/core/engine.rb', line 28

def initialize(&block)
  @name = nil
  @proc = Proc.new(&block) if block_given?
  @priority = 0
end

Instance Attribute Details

#matchesObject (readonly)

Returns the value of attribute matches.



25
26
27
# File 'lib/core/engine.rb', line 25

def matches
  @matches
end

#nameObject

Returns the value of attribute name.



24
25
26
# File 'lib/core/engine.rb', line 24

def name
  @name
end

#priorityObject

Returns the value of attribute priority.



23
24
25
# File 'lib/core/engine.rb', line 23

def priority
  @priority
end

#procObject (readonly)

Returns the value of attribute proc.



26
27
28
# File 'lib/core/engine.rb', line 26

def proc
  @proc
end

Instance Method Details

#==(a2) ⇒ Object



42
43
44
# File 'lib/core/engine.rb', line 42

def ==(a2)
  return @name == a2.name
end

#fire(match, engine = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/core/engine.rb', line 34

def fire(match, engine=nil)
  if @proc.arity == 2
    @proc.call(match, engine)
  else
    @proc.call(match)
  end
end