Class: Ravensat::Node

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ravensat/ast/node.rb

Direct Known Subclasses

InitialNode, OprNode, VarNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



6
7
8
# File 'lib/ravensat/ast/node.rb', line 6

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/ravensat/ast/node.rb', line 5

def children
  @children
end

Instance Method Details

#&(object) ⇒ Object



31
32
33
# File 'lib/ravensat/ast/node.rb', line 31

def &(object)
  AndNode.new(self, object)
end

#clauses_sizeObject



55
56
57
# File 'lib/ravensat/ast/node.rb', line 55

def clauses_size
  self.count{|node| node.is_a? AndNode} + 1
end

#cnf?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ravensat/ast/node.rb', line 43

def cnf?
  @children.map(&:cnf?).reduce(:&)
end

#eachObject

def each

yield(self)
@children.each do |child|
  child.each {|c| yield(c)}
end

end



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ravensat/ast/node.rb', line 17

def each
  case self
  when AndNode, OrNode
    @children.first.each{|c| yield(c)}
    yield(self)
    @children.last.each{|c| yield(c)}
  when NotNode
    yield(self)
    @children.first.each{|c| yield(c)}
  when VarNode
    yield(self)
  end
end

#to_sObject



39
40
41
# File 'lib/ravensat/ast/node.rb', line 39

def to_s
  self.class.name
end

#varsObject



47
48
49
# File 'lib/ravensat/ast/node.rb', line 47

def vars
  self.select{|node| node.is_a? VarNode}.uniq
end

#vars_sizeObject



51
52
53
# File 'lib/ravensat/ast/node.rb', line 51

def vars_size
  self.vars.size
end

#|(object) ⇒ Object



35
36
37
# File 'lib/ravensat/ast/node.rb', line 35

def |(object)
  OrNode.new(self, object)
end