Class: JSONP3::FunctionExpression
- Inherits:
-
Expression
- Object
- Expression
- JSONP3::FunctionExpression
- Defined in:
- lib/json_p3/filter.rb
Overview
A filter function call.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#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, args) ⇒ FunctionExpression
constructor
A new instance of FunctionExpression.
- #to_s ⇒ Object
Constructor Details
#initialize(token, name, args) ⇒ FunctionExpression
Returns a new instance of FunctionExpression.
354 355 356 357 358 |
# File 'lib/json_p3/filter.rb', line 354 def initialize(token, name, args) super(token) @name = name @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
350 351 352 |
# File 'lib/json_p3/filter.rb', line 350 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
350 351 352 |
# File 'lib/json_p3/filter.rb', line 350 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
374 375 376 377 378 379 |
# File 'lib/json_p3/filter.rb', line 374 def ==(other) self.class == other.class && @name == other.name && @args == other.args && @token == other.token end |
#evaluate(context) ⇒ Object
360 361 362 363 364 365 366 367 |
# File 'lib/json_p3/filter.rb', line 360 def evaluate(context) func = context.env.function_extensions.fetch(@name) args = @args.map { |arg| arg.evaluate(context) } unpacked_args = unpack_node_lists(func, args) func.call(*unpacked_args) rescue KeyError :nothing end |
#hash ⇒ Object
383 384 385 |
# File 'lib/json_p3/filter.rb', line 383 def hash [@name, @args, @token].hash end |
#to_s ⇒ Object
369 370 371 372 |
# File 'lib/json_p3/filter.rb', line 369 def to_s args = @args.map(&:to_s).join(", ") "#{@name}(#{args})" end |