Variable   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 58
Duplicated Lines 0 %
Metric Value
dl 0
loc 58
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A variables() 0 3 1
A to_cnf() 0 3 1
A tseitin() 0 3 1
A assign() 0 9 3
A nnf? 0 3 1
A reduced? 0 3 1
A to_s() 0 3 1
A not() 0 3 1
A initialize() 0 5 1
A cnf? 0 3 1
1
module PropLogic
2
  class Variable < Term
3
    def initialize(name = nil)
4
      @name = name || "v_#{object_id}"
5
      @terms = [].freeze
6
      freeze
7
    end
8
9
    public_class_method :new
10
11
    def to_s(*)
12
      @name
13
    end
14
15
    def nnf?
16
      true
17
    end
18
19
    def reduced?
20
      true
21
    end
22
23
    def to_cnf
24
      self
25
    end
26
27
    def tseitin(pool)
28
      self
29
    end
30
31
    def cnf?
32
      true
33
    end
34
35
    def variables
36
      [self]
37
    end
38
39
    def assign(trues, falses, variables = nil)
40
      if trues.include? self
41
        True
42
      elsif falses.include? self
43
        False
44
      else
45
        self
46
      end
47
    end
48
49
    # bypassing Term.get
50
    # @return [NotTerm] negated variable
51
    def not
52
      Term.__send__ :cached, NotTerm, self
53
    end
54
55
    alias_method :~, :not
56
    alias_method :-@, :not
57
58
59
  end
60
end
61