Skip to content

Commit c27c82d

Browse files
author
Matt Muller
committed
Add numeric as a comparable type
1 parent 57d77ea commit c27c82d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Unreleased Changes
2+
------------------
3+
4+
* Issue - Allow comparison of Numeric types (includes Float).
5+
16
1.6.1 (2022-03-07)
27
------------------
38

lib/jmespath/nodes/condition.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def optimize
2828

2929
class ComparatorCondition < Node
3030
COMPARATOR_TO_CONDITION = {}
31-
COMPARABLE_TYPES = [Integer, Float, String].freeze
31+
COMPARABLE_TYPES = [Numeric, String].freeze
3232

3333
def initialize(left, right, child)
3434
@left = left
@@ -43,8 +43,8 @@ def visit(_value)
4343
private
4444

4545
def comparable?(left_value, right_value)
46-
if COMPARABLE_TYPES.include?(left_value.class) && COMPARABLE_TYPES.include?(right_value.class)
47-
(left_value.class == right_value.class) || (left_value.is_a?(Numeric) && right_value.is_a?(Numeric))
46+
COMPARABLE_TYPES.any? do |type|
47+
left_value.is_a?(type) && right_value.is_a?(type)
4848
end
4949
end
5050
end

0 commit comments

Comments
 (0)