class JMESPath::Nodes::StartsWithFunction

Public Instance Methods

call(args) click to toggle source
# File lib/jmespath/nodes/function.rb, line 575
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