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?, #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.



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/jmespath/nodes/function.rb', line 589

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