Class: Ravensat::Node
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/ravensat/ast/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
6
7
8
|
# File 'lib/ravensat/ast/node.rb', line 6
def initialize
@children = []
end
|
Instance Attribute Details
#children ⇒ Object
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_size ⇒ Object
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
43
44
45
|
# File 'lib/ravensat/ast/node.rb', line 43
def cnf?
@children.map(&:cnf?).reduce(:&)
end
|
#each ⇒ Object
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_s ⇒ Object
39
40
41
|
# File 'lib/ravensat/ast/node.rb', line 39
def to_s
self.class.name
end
|
#vars ⇒ Object
47
48
49
|
# File 'lib/ravensat/ast/node.rb', line 47
def vars
self.select{|node| node.is_a? VarNode}.uniq
end
|
#vars_size ⇒ Object
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
|