Class: DRP::RuleMethod

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#depthObject (readonly)

Returns the value of attribute depth.



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

def depth
  @depth
end

#max_depthObject (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/rule_engine.rb', line 35

def expressed? 
  @depth < @max_depth
end

#weightObject



46
47
48
# File 'lib/rule_engine.rb', line 46

def weight
  @weight.value
end