Class: Ruleby::Core::ObjectPattern

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

Overview

This class represents a pattern that is looking for the existence of some object. It contains a list of ‘atoms’ that represent the properties of the class that we are looking for.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head, atoms) ⇒ ObjectPattern

Returns a new instance of ObjectPattern.



24
25
26
# File 'lib/core/patterns.rb', line 24

def initialize(head, atoms)
  @atoms = [head] + atoms     
end

Instance Attribute Details

#atomsObject (readonly)

Returns the value of attribute atoms.



22
23
24
# File 'lib/core/patterns.rb', line 22

def atoms
  @atoms
end

Instance Method Details

#==(pattern) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/core/patterns.rb', line 32

def ==(pattern)
  if pattern.class == self.class
    atoms = pattern.atoms
    if(@atoms.size == atoms.size)
      (0..@atoms.size).each do |i|
        if !(@atoms[i] == atoms[i])
          return false
        end
      end
      return true
    end
  end
  return false
end

#headObject



28
29
30
# File 'lib/core/patterns.rb', line 28

def head
  @atoms[0]
end

#to_sObject



47
48
49
# File 'lib/core/patterns.rb', line 47

def to_s
  return '(' + @atoms.join('|') + ')'
end