Class: AGIState

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

Overview

AGIState is meant to be subclassed to implement any state that needs to persist throughout an AGI session within the framework. By default, it can be sed to increase and reset failiure counters, and have an AGIStateException thrown when conditions are met.

Constant Summary collapse

@@failure_threshold =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf = {}) ⇒ AGIState

Returns a new instance of AGIState.



41
42
43
44
45
# File 'lib/AGIState.rb', line 41

def initialize(conf={})
  @failures = 0
  @failure_threshold = conf[:threshold] || @@failure_threshold
  @failure_threshold = conf[:failure_threshold] || @failure_threshold
end

Instance Attribute Details

#failure_thresholdObject (readonly)

Returns the value of attribute failure_threshold.



40
41
42
# File 'lib/AGIState.rb', line 40

def failure_threshold
  @failure_threshold
end

#failuresObject (readonly)

Returns the value of attribute failures.



39
40
41
# File 'lib/AGIState.rb', line 39

def failures
  @failures
end

Class Method Details

.failure_threshold=(threshold) ⇒ Object



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

def self.failure_threshold=(threshold)
  @@failure_threshold = threshold
end

Instance Method Details

#failure_incObject



49
50
51
52
53
54
# File 'lib/AGIState.rb', line 49

def failure_inc
  @failures += 1
  if @failures >= @failure_threshold then
    raise AGIStateFailure.new("Too many failures ( #{@failures} >= #{@failure_threshold})" )
  end
end

#failure_resetObject



55
56
57
58
59
60
# File 'lib/AGIState.rb', line 55

def failure_reset
  @failures = 0
  if @failures >= @failure_threshold then
    raise AGIStateFailure.new("Too many failures ( #{@failures} >= #{@failure_threshold})")
  end
end