Class: TPPlus::Nodes::OperatorNode

Inherits:
Object
  • Object
show all
Defined in:
lib/tp_plus/nodes/operator_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ OperatorNode

Returns a new instance of OperatorNode.



5
6
7
# File 'lib/tp_plus/nodes/operator_node.rb', line 5

def initialize(string)
  @string = string
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



4
5
6
# File 'lib/tp_plus/nodes/operator_node.rb', line 4

def string
  @string
end

Instance Method Details

#bang?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/tp_plus/nodes/operator_node.rb', line 9

def bang?
  @string == "!"
end

#boolean?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/tp_plus/nodes/operator_node.rb', line 22

def boolean?
  case @string
  when "&&", "||", "!"#, "==", "<>", ">", ">=", "<", "<="
    true
  else
    false
  end
end

#eval(context, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tp_plus/nodes/operator_node.rb', line 31

def eval(context,options={})
  if options[:opposite]
    case @string
    when "=="
      "<>"
    when "!=", "<>"
      "="
    when ">"
      "<="
    when "<"
      ">="
    when ">="
      "<"
    when "<="
      ">"
    when "!"
      ""
    when "||"
      " AND "
    when "&&"
      " OR "
    when "DIV"
      " MOD "
    else
      "#{@string}"
    end
  else
    case @string
    when "=="
      "="
    when "!="
      "<>"
    when "&&"
      " AND "
    when "||"
      " OR "
    when "%"
      " MOD "
    when "DIV"
      " DIV "
    else
      "#{@string}"
    end
  end
end

#requires_mixed_logic?(context) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/tp_plus/nodes/operator_node.rb', line 13

def requires_mixed_logic?(context)
  case @string
  when "&&", "||", "!"
    true
  else
    false
  end
end