Skip to content

Commit 9c7d316

Browse files
authored
Merge pull request #57 from mtichner/patch-1
Allow comparison of Integers and Numeric types
2 parents a085656 + 90ab191 commit 9c7d316

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Allow comparison of Numeric types (includes Float).
5+
46
* Issue - Add jmespath.rb to gemspec executables.
57

68
1.6.1 (2022-03-07)

lib/jmespath/nodes/condition.rb

+1-1
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, String].freeze
31+
COMPARABLE_TYPES = [Numeric, String].freeze
3232

3333
def initialize(left, right, child)
3434
@left = left

spec/compliance/filters.json

+27
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,33 @@
465465
}
466466
]
467467
},
468+
{
469+
"given": {"foo": [{"length": 170},
470+
{"length": 175.5},
471+
{"length": 185}]},
472+
"cases": [
473+
{
474+
"comment": "Less than number",
475+
"expression": "foo[?length < `180`]",
476+
"result": [{"length": 170}, {"length": 175.5}]
477+
},
478+
{
479+
"comment": "Less than or equal to number",
480+
"expression": "foo[?length <= `175.5`]",
481+
"result": [{"length": 170}, {"length": 175.5}]
482+
},
483+
{
484+
"comment": "Greater than number",
485+
"expression": "foo[?length > `170`]",
486+
"result": [{"length": 175.5}, {"length": 185}]
487+
},
488+
{
489+
"comment": "Greater than or equal to number",
490+
"expression": "foo[?length >= `175.5`]",
491+
"result": [{"length": 175.5}, {"length": 185}]
492+
}
493+
]
494+
},
468495
{
469496
"given": {
470497
"foo": ["2010-02-01", "2011-05-01"]

0 commit comments

Comments
 (0)