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 ⇒ Object
-
#initialize(action, match, counter = 0) ⇒ Activation
constructor
A new instance of Activation.
- #to_s ⇒ Object
Constructor Details
#initialize(action, match, counter = 0) ⇒ Activation
Returns a new instance of Activation.
49 50 51 52 53 54 55 56 |
# File 'lib/core/engine.rb', line 49 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.
46 47 48 |
# File 'lib/core/engine.rb', line 46 def action @action end |
#counter ⇒ Object
Returns the value of attribute counter.
47 48 49 |
# File 'lib/core/engine.rb', line 47 def counter @counter end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
46 47 48 |
# File 'lib/core/engine.rb', line 46 def match @match end |
#used ⇒ Object
Returns the value of attribute used.
47 48 49 |
# File 'lib/core/engine.rb', line 47 def used @used end |
Instance Method Details
#<=>(a2) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/core/engine.rb', line 63 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
74 75 76 |
# File 'lib/core/engine.rb', line 74 def ==(a2) return a2 != nil && @action == a2.action && @match == a2.match end |
#fire ⇒ Object
58 59 60 61 |
# File 'lib/core/engine.rb', line 58 def fire() @used = true @action.fire @match end |
#to_s ⇒ Object
78 79 80 |
# File 'lib/core/engine.rb', line 78 def to_s return "[#{@action.name}-#{object_id}|#{@counter}|#{@action.priority}|#{@match.recency.join(',')}|#{@match.to_s}] " end |