Class: JMESPath::Nodes::SortFunction Private

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

Overview

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.

API:

  • private

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.

API:

  • private



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/jmespath/nodes/function.rb', line 375

def call(args)
  if args.count == 1
    value = args.first
    if Array === value
      value.sort do |a, b|
        a_type = get_type(a)
        b_type = get_type(b)
        if (a_type == STRING_TYPE || a_type == NUMBER_TYPE) && a_type == b_type
          a <=> b
        else
          return maybe_raise Errors::InvalidTypeError, "function sort() expects values to be an array of numbers or integers"
        end
      end
    else
      return maybe_raise Errors::InvalidTypeError, "function sort() expects values to be an array of numbers or integers"
    end
  else
    return maybe_raise Errors::InvalidArityError, "function sort() expects one argument"
  end
end