class JMESPath::Nodes::EndsWithFunction

Public Instance Methods

call(args) click to toggle source
# File lib/jmespath/nodes/function.rb, line 549
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"
      return maybe_raise Errors::InvalidTypeError, msg
    end
    if suffix_type != STRING_TYPE
      msg = "function ends_with() expects second argument to be a string"
      return maybe_raise Errors::InvalidTypeError, msg
    end
    search.end_with?(suffix)
  else
    msg = "function ends_with() expects two arguments"
    return maybe_raise Errors::InvalidArityError, msg
  end
end