Class: JSONP3::Path::FunctionExpression
- Inherits:
-
Expression
- Object
- Expression
- JSONP3::Path::FunctionExpression
- Defined in:
- lib/json_p3/path/filter.rb
Overview
A filter function call.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#func ⇒ Object
readonly
Returns the value of attribute func.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Expression
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #evaluate(context) ⇒ Object
- #hash ⇒ Object
-
#initialize(token, name, func, args) ⇒ FunctionExpression
constructor
A new instance of FunctionExpression.
- #to_s ⇒ Object
Constructor Details
#initialize(token, name, func, args) ⇒ FunctionExpression
Returns a new instance of FunctionExpression.
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
352 353 354 |
# File 'lib/json_p3/path/filter.rb', line 352 def args @args end |
#func ⇒ Object (readonly)
Returns the value of attribute func.
352 353 354 |
# File 'lib/json_p3/path/filter.rb', line 352 def func @func end |
#name ⇒ Object (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 |
#hash ⇒ Object
386 387 388 |
# File 'lib/json_p3/path/filter.rb', line 386 def hash [@name, @args, @token].hash end |
#to_s ⇒ Object
372 373 374 375 |
# File 'lib/json_p3/path/filter.rb', line 372 def to_s args = @args.join(", ") "#{@name}(#{args})" end |