Class: Wongi::Engine::WME

Inherits:
Struct
  • Object
show all
Defined in:
lib/wongi-engine/wme.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of object



2
3
4
# File 'lib/wongi-engine/wme.rb', line 2

def object
  @object
end

#predicateObject

Returns the value of attribute predicate

Returns:

  • (Object)

    the current value of predicate



2
3
4
# File 'lib/wongi-engine/wme.rb', line 2

def predicate
  @predicate
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



2
3
4
# File 'lib/wongi-engine/wme.rb', line 2

def subject
  @subject
end

Class Method Details

.from_concrete_template(template) ⇒ Object



3
4
5
6
7
# File 'lib/wongi-engine/wme.rb', line 3

def self.from_concrete_template(template)
  raise "template #{template} is not concrete" unless template.concrete?

  new(template.subject, template.predicate, template.object)
end

Instance Method Details

#=~(template) ⇒ Object

Parameters:

  • template

    Wongi::Engine::Template

Raises:



14
15
16
17
18
19
# File 'lib/wongi-engine/wme.rb', line 14

def =~(template)
  raise Wongi::Engine::Error, "Cannot match a WME against a #{template.class}" unless template.is_a?(Template)

  result = match_member(subject, template.subject) & match_member(predicate, template.predicate) & match_member(object, template.object)
  result if result.match?
end

#dupObject



9
10
11
# File 'lib/wongi-engine/wme.rb', line 9

def dup
  self.class.new(subject, predicate, object)
end

#inspectObject



21
22
23
# File 'lib/wongi-engine/wme.rb', line 21

def inspect
  "{#{subject.inspect} #{predicate.inspect} #{object.inspect}}"
end

#to_sObject



25
26
27
# File 'lib/wongi-engine/wme.rb', line 25

def to_s
  inspect
end