Class: DRP::RuleMethod
- Inherits:
-
Object
- Object
- DRP::RuleMethod
- Defined in:
- lib/rule_engine.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#max_depth ⇒ Object
readonly
Returns the value of attribute max_depth.
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #expressed? ⇒ Boolean
-
#initialize(drp_instance, method_name, weight_factory, max_depth) ⇒ RuleMethod
constructor
A new instance of RuleMethod.
- #weight ⇒ Object
Constructor Details
#initialize(drp_instance, method_name, weight_factory, max_depth) ⇒ RuleMethod
Returns a new instance of RuleMethod.
28 29 30 31 32 33 |
# File 'lib/rule_engine.rb', line 28 def initialize drp_instance, method_name, weight_factory, max_depth @method = drp_instance.method method_name @max_depth = max_depth.value drp_instance @weight = weight_factory.call self, drp_instance @depth = 0 end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
26 27 28 |
# File 'lib/rule_engine.rb', line 26 def depth @depth end |
#max_depth ⇒ Object (readonly)
Returns the value of attribute max_depth.
26 27 28 |
# File 'lib/rule_engine.rb', line 26 def max_depth @max_depth end |
Instance Method Details
#call(*args) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rule_engine.rb', line 39 def call *args @depth += 1 result = @method.call *args @depth -= 1 result end |
#expressed? ⇒ Boolean
35 36 37 |
# File 'lib/rule_engine.rb', line 35 def expressed? @depth < @max_depth end |
#weight ⇒ Object
46 47 48 |
# File 'lib/rule_engine.rb', line 46 def weight @weight.value end |