Class: Ruleby::Core::Fact

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

Overview

A fact is an object that is stored in working memory. The rules in the system will either look for the existence or absence of particular facts.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, token) ⇒ Fact

Returns a new instance of Fact.



117
118
119
120
# File 'lib/core/engine.rb', line 117

def initialize(object, token)
  @token = token      
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



115
116
117
# File 'lib/core/engine.rb', line 115

def object
  @object
end

#recencyObject

Returns the value of attribute recency.



114
115
116
# File 'lib/core/engine.rb', line 114

def recency
  @recency
end

#tokenObject

Returns the value of attribute token.



113
114
115
# File 'lib/core/engine.rb', line 113

def token
  @token
end

Instance Method Details

#==(fact) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/core/engine.rb', line 126

def ==(fact)
  if fact.is_a? Fact
    fact != nil && fact.id == id
  else
    fact != nil && fact.object_id == id
  end
end

#idObject



122
123
124
# File 'lib/core/engine.rb', line 122

def id
  return object.object_id
end

#to_sObject



134
135
136
# File 'lib/core/engine.rb', line 134

def to_s
  "[Fact |#{@recency}|#{@object.to_s}]"
end