Class: KBS::Rule
- Inherits:
-
Object
- Object
- KBS::Rule
- Defined in:
- lib/kbs/rule.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Instance Method Summary collapse
- #fire(facts) ⇒ Object
-
#initialize(name, conditions: [], action: nil, priority: 0) {|_self| ... } ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(name, conditions: [], action: nil, priority: 0) {|_self| ... } ⇒ Rule
Returns a new instance of Rule.
8 9 10 11 12 13 14 15 16 |
# File 'lib/kbs/rule.rb', line 8 def initialize(name, conditions: [], action: nil, priority: 0, &block) @name = name @conditions = conditions @action = action @priority = priority @fired_count = 0 yield self if block_given? end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'lib/kbs/rule.rb', line 6 def action @action end |
#conditions ⇒ Object
Returns the value of attribute conditions.
6 7 8 |
# File 'lib/kbs/rule.rb', line 6 def conditions @conditions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/kbs/rule.rb', line 5 def name @name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
5 6 7 |
# File 'lib/kbs/rule.rb', line 5 def priority @priority end |
Instance Method Details
#fire(facts) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kbs/rule.rb', line 18 def fire(facts) @fired_count += 1 return unless @action bindings = extract_bindings(facts) # Support both 1-parameter and 2-parameter actions if @action.arity == 1 || @action.arity == -1 @action.call(facts) else @action.call(facts, bindings) end end |