Class: JMESPath::Nodes::StartsWithFunction 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.



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/jmespath/nodes/function.rb', line 574

def call(args)
  if args.count == 2
    search, prefix = args
    search_type = get_type(search)
    prefix_type = get_type(prefix)
    if search_type != STRING_TYPE
      msg = "function starts_with() expects first argument to be a string"
      return maybe_raise Errors::InvalidTypeError, msg
    end
    if prefix_type != STRING_TYPE
      msg = "function starts_with() expects second argument to be a string"
      return maybe_raise Errors::InvalidTypeError, msg
    end
    search.start_with?(prefix)
  else
    msg = "function starts_with() expects two arguments"
    return maybe_raise Errors::InvalidArityError, msg
  end
end