Class: Ruleby::Core::Activation
- Inherits:
-
Object
- Object
- Ruleby::Core::Activation
- Defined in:
- lib/core/engine.rb
Overview
An activation is an action/match pair that is executed if a rule is matched. It also contains metadata that can be used for conflict resolution if two rules are satisfied by the same fact.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#used ⇒ Object
Returns the value of attribute used.
Instance Method Summary collapse
- #<=>(a2) ⇒ Object
- #==(a2) ⇒ Object
- #fire(engine = nil) ⇒ Object
-
#initialize(action, match, counter = 0) ⇒ Activation
constructor
A new instance of Activation.
- #modify(match) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(action, match, counter = 0) ⇒ Activation
Returns a new instance of Activation.
54 55 56 57 58 59 60 61 |
# File 'lib/core/engine.rb', line 54 def initialize(action, match, counter=0) @action = action @match = match @match.recency.sort! @match.recency.reverse! @counter = counter @used = false end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
51 52 53 |
# File 'lib/core/engine.rb', line 51 def action @action end |
#counter ⇒ Object
Returns the value of attribute counter.
52 53 54 |
# File 'lib/core/engine.rb', line 52 def counter @counter end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
51 52 53 |
# File 'lib/core/engine.rb', line 51 def match @match end |
#used ⇒ Object
Returns the value of attribute used.
52 53 54 |
# File 'lib/core/engine.rb', line 52 def used @used end |
Instance Method Details
#<=>(a2) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/core/engine.rb', line 68 def <=>(a2) return @counter <=> a2.counter if @counter != a2.counter return @action.priority <=> a2.action.priority if @action.priority != a2.action.priority # NOTE in order for this to work, the array must be reverse sorted i = 0; while @match.recency[i] == a2.match.recency[i] && i < @match.recency.size-1 && i < a2.match.recency.size-1 i += 1 end return @match.recency[i] <=> a2.match.recency[i] end |
#==(a2) ⇒ Object
79 80 81 |
# File 'lib/core/engine.rb', line 79 def ==(a2) return a2 != nil && @action == a2.action && @match == a2.match end |
#fire(engine = nil) ⇒ Object
63 64 65 66 |
# File 'lib/core/engine.rb', line 63 def fire(engine=nil) @used = true @action.fire @match, engine end |
#modify(match) ⇒ Object
83 84 85 86 |
# File 'lib/core/engine.rb', line 83 def modify(match) @match = match # should we update recency, too? end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/core/engine.rb', line 88 def to_s return "[#{@action.name}-#{object_id}|#{@counter}|#{@action.priority}|#{@match.recency.join(',')}|#{@match.to_s}] " end |