Class: JSONP3::Path::FunctionExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/json_p3/path/filter.rb

Overview

A filter function call.

Instance Attribute Summary collapse

Attributes inherited from Expression

#token

Instance Method Summary collapse

Constructor Details

#initialize(token, name, func, args) ⇒ FunctionExpression

Returns a new instance of FunctionExpression.

Parameters:



357
358
359
360
361
362
# File 'lib/json_p3/path/filter.rb', line 357

def initialize(token, name, func, args)
  super(token)
  @name = name
  @func = func
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



352
353
354
# File 'lib/json_p3/path/filter.rb', line 352

def args
  @args
end

#funcObject (readonly)

Returns the value of attribute func.



352
353
354
# File 'lib/json_p3/path/filter.rb', line 352

def func
  @func
end

#nameObject (readonly)

Returns the value of attribute name.



352
353
354
# File 'lib/json_p3/path/filter.rb', line 352

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



377
378
379
380
381
382
# File 'lib/json_p3/path/filter.rb', line 377

def ==(other)
  self.class == other.class &&
    @name == other.name &&
    @args == other.args &&
    @token == other.token
end

#evaluate(context) ⇒ Object



364
365
366
367
368
369
370
# File 'lib/json_p3/path/filter.rb', line 364

def evaluate(context)
  args = @args.map { |arg| arg.evaluate(context) }
  unpacked_args = unpack_node_lists(@func, args)
  @func.call(*unpacked_args)
rescue KeyError
  :nothing
end

#hashObject



386
387
388
# File 'lib/json_p3/path/filter.rb', line 386

def hash
  [@name, @args, @token].hash
end

#to_sObject



372
373
374
375
# File 'lib/json_p3/path/filter.rb', line 372

def to_s
  args = @args.join(", ")
  "#{@name}(#{args})"
end