class TPPlus::Nodes::ExpressionNode
Attributes
left_op[R]
op[R]
right_op[R]
Public Class Methods
new(left_op, op_string, right_op)
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 5 def initialize(left_op, op_string, right_op) @left_op = left_op @op = OperatorNode.new(op_string) @right_op = right_op end
Public Instance Methods
boolean_result?()
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 31 def boolean_result? case @op.string when "&&","||","!","==","<>",">",">=","<","<=" true else false end end
contains_expression?()
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 26 def contains_expression? [@left_op, @right_op].map {|op| op.is_a? ExpressionNode }.any? || [@left_op, @right_op].map { |op| op.is_a? ParenExpressionNode }.any? end
eval(context,options={})
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 64 def eval(context,options={}) options[:force_parens] = true if grouped? string_val(context, options) end
grouped?()
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 11 def grouped? return false if @right_op.nil? # this is for NOT (!) operator @left_op.is_a?(ParenExpressionNode) || @right_op.is_a?(ParenExpressionNode) end
requires_mixed_logic?(context)
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 17 def requires_mixed_logic?(context) contains_expression? || grouped? || [@op, @left_op, @right_op].map { |op| next if op.nil? op.requires_mixed_logic?(context) }.any? end
string_val(context, options={})
click to toggle source
# File lib/tp_plus/nodes/expression_node.rb, line 40 def string_val(context, options={}) if @op.bang? # this is for skip conditions, which do not # support mixed logic if options[:disable_mixed_logic] "#{@left_op.eval(context)}=OFF" else "#{@op.eval(context,options)}#{@left_op.eval(context)}" end else if @op.boolean? # if operator is &&, || or !, we flip the operator and the operands left = @left_op.eval(context, options) op = @op.eval(context, options) right = @right_op.eval(context, options) [left, op, right].reject(&:empty?).join('') else # flip the operator if options[:opposite] # flip the operands only if opposite and the operand is an expression "#{@left_op.eval(context, opposite: ((@left_op.is_a?(ExpressionNode) || @left_op.is_a?(UnaryExpressionNode))&& options[:opposite]))}#{@op.eval(context, options)}#{@right_op.eval(context, opposite: ((@right_op.is_a?(ExpressionNode) || @right_op.is_a?(UnaryExpressionNode)) && options[:opposite]))}" end end end