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.



290
291
292
293
294
# File 'lib/cel/ast/elements.rb', line 290

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

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



286
287
288
# File 'lib/cel/ast/elements.rb', line 286

def op
  @op
end

#operandsObject (readonly)

Returns the value of attribute operands.



286
287
288
# File 'lib/cel/ast/elements.rb', line 286

def operands
  @operands
end

#typeObject

Returns the value of attribute type.



288
289
290
# File 'lib/cel/ast/elements.rb', line 288

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



296
297
298
299
300
301
302
303
304
# File 'lib/cel/ast/elements.rb', line 296

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

#to_sObject



306
307
308
309
310
# File 'lib/cel/ast/elements.rb', line 306

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

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