Class: Cel::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/cel/ast/elements.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op, operands) ⇒ Operation

Returns a new instance of Operation.



545
546
547
548
549
# File 'lib/cel/ast/elements.rb', line 545

def initialize(op, operands)
  @op = op
  @operands = operands
  @type = TYPES[:any]
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



541
542
543
# File 'lib/cel/ast/elements.rb', line 541

def op
  @op
end

#operandsObject (readonly)

Returns the value of attribute operands.



541
542
543
# File 'lib/cel/ast/elements.rb', line 541

def operands
  @operands
end

#typeObject

Returns the value of attribute type.



543
544
545
# File 'lib/cel/ast/elements.rb', line 543

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



551
552
553
554
555
556
557
558
559
560
561
562
# File 'lib/cel/ast/elements.rb', line 551

def ==(other)
  case other
  when Array
    other.size == @operands.size + 1 &&
      other.first == @op &&
      other.slice(1..-1).zip(@operands).all? { |x1, x2| x1 == x2 }
  when Operation
    @op == other.op && @type == other.type && @operands == other.operands
  else
    super
  end
end

#to_sObject



568
569
570
571
572
# File 'lib/cel/ast/elements.rb', line 568

def to_s
  return "#{@op}#{@operands.first}" if @operands.size == 1

  @operands.join(" #{@op} ")
end

#unary?Boolean

Returns:

  • (Boolean)


564
565
566
# File 'lib/cel/ast/elements.rb', line 564

def unary?
  @operands.size == 1
end