Module: JMESPath::Nodes::NumberComparator Private

Includes:
TypeChecker
Included in:
MaxByFunction, MinByFunction
Defined in:
lib/jmespath/nodes/function.rb

This module is part of a private API. You should avoid using this module 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

Instance Method Summary collapse

Methods included from TypeChecker

#get_type

Instance Method Details

#number_compare(mode, *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.



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/jmespath/nodes/function.rb', line 430

def number_compare(mode, *args)
  if args.count == 2
    values = args[0]
    expression = args[1]
    if get_type(values) == ARRAY_TYPE && get_type(expression) == EXPRESSION_TYPE
      values.send(mode) do |entry|
        value = expression.eval(entry)
        if get_type(value) == NUMBER_TYPE
          value
        else
          return maybe_raise Errors::InvalidTypeError, "function #{mode}() expects values to be an numbers"
        end
      end
    else
      return maybe_raise Errors::InvalidTypeError, "function #{mode}() expects an array and an expression"
    end
  else
    return maybe_raise Errors::InvalidArityError, "function #{mode}() expects two arguments"
  end
end