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.



537
538
539
540
541
# File 'lib/cel/ast/elements.rb', line 537

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

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



533
534
535
# File 'lib/cel/ast/elements.rb', line 533

def op
  @op
end

#operandsObject (readonly)

Returns the value of attribute operands.



533
534
535
# File 'lib/cel/ast/elements.rb', line 533

def operands
  @operands
end

#typeObject

Returns the value of attribute type.



535
536
537
# File 'lib/cel/ast/elements.rb', line 535

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/cel/ast/elements.rb', line 543

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



556
557
558
559
560
# File 'lib/cel/ast/elements.rb', line 556

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

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