Class: JMESPath::Nodes::EndsWithFunction Private

Inherits:
Function show all
Includes:
TypeChecker
Defined in:
lib/jmespath/nodes/function.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from TypeChecker

TypeChecker::ARRAY_TYPE, TypeChecker::BOOLEAN_TYPE, TypeChecker::EXPRESSION_TYPE, TypeChecker::NULL_TYPE, TypeChecker::NUMBER_TYPE, TypeChecker::OBJECT_TYPE, TypeChecker::STRING_TYPE, TypeChecker::TYPE_NAMES

Constants inherited from Function

Function::FUNCTIONS

Instance Method Summary collapse

Methods included from TypeChecker

#get_type

Methods inherited from Function

create, #initialize, #optimize, #visit

Methods inherited from Node

#chains_with?, #hash_like?, #optimize, #visit

Constructor Details

This class inherits a constructor from JMESPath::Nodes::Function

Instance Method Details

#call(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/jmespath/nodes/function.rb', line 503

def call(args)
  if args.count == 2
    search, suffix = args
    search_type = get_type(search)
    suffix_type = get_type(suffix)
    if search_type != STRING_TYPE
      msg = "function ends_with() expects first argument to be a string"
      raise Errors::InvalidTypeError, msg
    end
    if suffix_type != STRING_TYPE
      msg = "function ends_with() expects second argument to be a string"
      raise Errors::InvalidTypeError, msg
    end
    search.end_with?(suffix)
  else
    msg = "function ends_with() expects two arguments"
    raise Errors::InvalidArityError, msg
  end
end