Skip to content

Commit

Permalink
Add numeric as a comparable type
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Nov 21, 2022
1 parent 57d77ea commit c27c82d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased Changes
------------------

* Issue - Allow comparison of Numeric types (includes Float).

1.6.1 (2022-03-07)
------------------

Expand Down
6 changes: 3 additions & 3 deletions lib/jmespath/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def optimize

class ComparatorCondition < Node
COMPARATOR_TO_CONDITION = {}
COMPARABLE_TYPES = [Integer, Float, String].freeze
COMPARABLE_TYPES = [Numeric, String].freeze

def initialize(left, right, child)
@left = left
Expand All @@ -43,8 +43,8 @@ def visit(_value)
private

def comparable?(left_value, right_value)
if COMPARABLE_TYPES.include?(left_value.class) && COMPARABLE_TYPES.include?(right_value.class)
(left_value.class == right_value.class) || (left_value.is_a?(Numeric) && right_value.is_a?(Numeric))
COMPARABLE_TYPES.any? do |type|
left_value.is_a?(type) && right_value.is_a?(type)
end
end
end
Expand Down

0 comments on commit c27c82d

Please sign in to comment.