json-logic-rb 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 975d191c041cd7afd3e3ab977d01944e00693ec7320e6418ae312d71afa67d7f
4
- data.tar.gz: 9b871c8f3b53fbc5cf3e2dbd180a556e5815940c536da6e2c248bf8b66c9be8d
3
+ metadata.gz: e78d982fcb2d524f9cf465fe79b6248a4b0db63b188059e712ec2eaeac4f92fe
4
+ data.tar.gz: d3088cd8e398155b9d94e5c9c34435b4af1fcd0c7ba71f6aedb7333802372218
5
5
  SHA512:
6
- metadata.gz: eef9bc4ce561c092cc5bd7885b9f69051e4aa0712dd15e93c92f4dd32c177570472a401e7bdce65565cee4ee8b80e3ebc3afaa46a0fab91cb1f730c83f0e1a83
7
- data.tar.gz: fce35e13727e2d30e827c787c5543eb13005c38a59e44abcb8a340b486d1c814d4367d297dc20826b845dd7da98c193b2fa1bf0a521d6aa70bff2847da51eb6c
6
+ metadata.gz: c960976bb1311c6ff7528464a62a7e655702bca7565c9594fa11a1b103c84f3beb045934c387adde643d9f21fbf4daeaf4c46f6e55a96e5866f95b5b86163da3
7
+ data.tar.gz: f623b9be9b861890f73d7284050b8fd26debfc4d928495ed5ef406ccc0d4abbc7cec93ddf23485bcd199f0b85f7cec37cba0232ffa8589db429d80c28c5d6ae8
@@ -21,13 +21,20 @@ module JsonLogic
21
21
  end
22
22
  end
23
23
 
24
+ def to_primitive(v)
25
+ case v
26
+ when Array then v.join(',')
27
+ else v
28
+ end
29
+ end
30
+
24
31
  def num(v)
25
32
  case v
26
33
  when Numeric then v.to_f
27
34
  when TrueClass then 1.0
28
35
  when FalseClass then 0.0
29
36
  when NilClass then 0.0
30
- when Array then num(v.join(','))
37
+ when Array then num(to_primitive(v))
31
38
  when String
32
39
  s = v.strip
33
40
  return 0.0 if s.empty?
@@ -44,23 +51,36 @@ module JsonLogic
44
51
  def eq(a, b)
45
52
  if a.class == b.class
46
53
  if a.is_a?(Numeric)
47
- return false if a.to_f.nan? || b.to_f.nan?
48
- return a.to_f == b.to_f
54
+ ax = a.to_f; bx = b.to_f
55
+ return false if ax.nan? || bx.nan?
56
+ return ax == bx
49
57
  else
50
58
  return a.eql?(b)
51
59
  end
52
60
  end
53
61
 
54
- if a.is_a?(TrueClass) || a.is_a?(FalseClass) || b.is_a?(TrueClass) || b.is_a?(FalseClass)
55
- na = num(a); nb = num(b)
56
- return false if na.nan? || nb.nan?
57
- return na == nb
62
+ if a.nil? && b.nil?
63
+ return true
64
+ elsif a.nil? || b.nil?
65
+ return false
66
+ end
67
+
68
+ if a.is_a?(TrueClass) || a.is_a?(FalseClass)
69
+ return eq(num(a), b)
70
+ end
71
+ if b.is_a?(TrueClass) || b.is_a?(FalseClass)
72
+ return eq(a, num(b))
58
73
  end
59
74
 
60
75
  if (a.is_a?(String) && b.is_a?(Numeric)) || (a.is_a?(Numeric) && b.is_a?(String))
61
- na = num(a); nb = num(b)
62
- return false if na.nan? || nb.nan?
63
- return na == nb
76
+ ax = num(a); bx = num(b)
77
+ return false if ax.nan? || bx.nan?
78
+ return ax == bx
79
+ end
80
+
81
+ if (a.is_a?(Array) && (b.is_a?(String) || b.is_a?(Numeric))) ||
82
+ (b.is_a?(Array) && (a.is_a?(String) || a.is_a?(Numeric)))
83
+ return eq(to_primitive(a), to_primitive(b))
64
84
  end
65
85
 
66
86
  false
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module JsonLogic; VERSION = '0.1.3'; end
3
+ module JsonLogic; VERSION = '0.1.4'; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-logic-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tavrel Kate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-31 00:00:00.000000000 Z
11
+ date: 2025-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby implementation of JsonLogic. JsonLogic rules are JSON trees. The
14
14
  engine walks that tree and returns a Ruby value. Ships with a compliance runner