shiny_json_logic 0.2.0 → 0.2.1

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: a20fb7e281bf025ff316d3792c9bc2318690479d45e7191f9f4a816786398c2f
4
- data.tar.gz: f35df94f77e3338b55f8802b482c41b033223038d778ba3dd611ce059968a42f
3
+ metadata.gz: 29b936cfc360867d9ba05f4dbc9f0c8b952f17c6932a02b4db123fb8f9621f0b
4
+ data.tar.gz: 7e8d052e9dc1b88cd5fd7e76d8a87c6554d51fd611c204877617268179984d6e
5
5
  SHA512:
6
- metadata.gz: c64e34362fd188c4b5b32f37494e9a0449b96e030f67591e57e19e4dfdf31c3d646c0324e90ad09ffa7efb7816547141a44865482c36558d30f00f498e30fcda
7
- data.tar.gz: 5b5df2b33a6651852287cbb04aa107d8a5a1145b73cae91c7df344224f26abdc3d191a8aaf0ebe447d01f79d3e2cb283c6d09a5c2b2d238dfe9af930eda6d716
6
+ metadata.gz: 4afa245d28e2a10f11d26a3a136316389c85c90517d169598cc8be61a11a77164b68a88818dd90c47e1d8767ea2449dfa1a17946cefdc52943b47696ea51b800
7
+ data.tar.gz: a77c9185c0f452e8f0c76e78c351150a7975b78dda73532e458bc94ad78b479ddef26e019528f0cf4c7db01c53072f392675f8506929950a02c9f6faefff819b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
+ ## [0.2.1] - 2026-02-02
5
+ ### Changed
6
+ - Improves compatibility of subtraction operator
7
+
4
8
  ## [0.2.0] - 2026-02-02
5
9
  ### Changed
6
10
  - Improves compatibility of division operator
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiny_json_logic (0.2.0)
4
+ shiny_json_logic (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/badges/compat.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "label": "compat",
4
- "message": "77.7% (875/1126)",
4
+ "message": "78.8% (887/1126)",
5
5
  "color": "red"
6
6
  }
@@ -0,0 +1,25 @@
1
+ module ShinyJsonLogic
2
+ module Numericals
3
+ module Numerify
4
+ def numerified
5
+ @numerified ||=
6
+ rules.map do |rule|
7
+ numerify(rule)
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def numerify(value)
14
+ return value.to_f if value.is_a?(Numeric)
15
+ return 0.0 if value == ""
16
+ return value.to_f if value.is_a?(String) && value.match?(/\A[+-]?\d*.?\d+\z/)
17
+ return 0 if value == false
18
+ return 1 if value == true
19
+ return nil if value.nil?
20
+
21
+ raise TypeError, "Cannot convert #{value.inspect} to a number"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,10 +1,13 @@
1
1
  require "shiny_json_logic/operations/base"
2
2
  require "shiny_json_logic/numericals/with_error_handling"
3
+ require "shiny_json_logic/numericals/numerify"
3
4
 
4
5
  module ShinyJsonLogic
5
6
  module Operations
6
7
  class Division < Base
7
8
  include Numericals::WithErrorHandling
9
+ include Numericals::Numerify
10
+
8
11
  protected
9
12
 
10
13
  def run
@@ -14,7 +17,7 @@ module ShinyJsonLogic
14
17
  safe_arithmetic do
15
18
  self.rules = [1, *rules] if rules.size < 2
16
19
 
17
- numberified.reduce(:/)
20
+ numerified.reduce(:/)
18
21
  end
19
22
  end
20
23
 
@@ -33,14 +36,6 @@ module ShinyJsonLogic
33
36
 
34
37
  error.id
35
38
  end
36
-
37
- def numberified
38
- rules.map do |rule|
39
- next rule.to_f if rule.is_a?(Numeric) || rule.is_a?(String)
40
- next 0 if rule == false
41
- next 1 if rule == true
42
- end
43
- end
44
39
  end
45
40
  end
46
41
  end
@@ -1,19 +1,31 @@
1
1
  require "shiny_json_logic/operations/base"
2
2
  require "shiny_json_logic/numericals/with_error_handling"
3
+ require "shiny_json_logic/numericals/numerify"
3
4
 
4
5
  module ShinyJsonLogic
5
6
  module Operations
6
7
  class Subtraction < Base
7
8
  include Numericals::WithErrorHandling
9
+ include Numericals::Numerify
8
10
 
9
11
  protected
10
12
 
11
13
  def run
12
14
  safe_arithmetic do
13
- return rules.first.to_f * -1 if rules.size == 1
14
- rules.map(&:to_f).reduce(:-)
15
+ return numerified.first * -1 if rules.size == 1
16
+
17
+ numerified.reduce(:-)
15
18
  end
16
19
  end
20
+
21
+ private
22
+
23
+ def numerify(value)
24
+ val = super
25
+ return 0 if val.nil?
26
+
27
+ val
28
+ end
17
29
  end
18
30
  end
19
31
  end
@@ -1,3 +1,3 @@
1
1
  module ShinyJsonLogic
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/results/ruby.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "totals": {
3
3
  "shiny_json_logic": {
4
- "passed": 881,
4
+ "passed": 887,
5
5
  "total": 1126
6
6
  }
7
7
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiny_json_logic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Moyano
@@ -130,6 +130,7 @@ files:
130
130
  - lib/shiny_json_logic.rb
131
131
  - lib/shiny_json_logic/engine.rb
132
132
  - lib/shiny_json_logic/errors/base.rb
133
+ - lib/shiny_json_logic/numericals/numerify.rb
133
134
  - lib/shiny_json_logic/numericals/with_error_handling.rb
134
135
  - lib/shiny_json_logic/operations/addition.rb
135
136
  - lib/shiny_json_logic/operations/all.rb