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.



525
526
527
528
529
# File 'lib/cel/ast/elements.rb', line 525

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

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



521
522
523
# File 'lib/cel/ast/elements.rb', line 521

def op
  @op
end

#operandsObject (readonly)

Returns the value of attribute operands.



521
522
523
# File 'lib/cel/ast/elements.rb', line 521

def operands
  @operands
end

#typeObject

Returns the value of attribute type.



523
524
525
# File 'lib/cel/ast/elements.rb', line 523

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/cel/ast/elements.rb', line 531

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



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

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

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