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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/badges/compat.json +1 -1
- data/lib/shiny_json_logic/numericals/numerify.rb +25 -0
- data/lib/shiny_json_logic/operations/division.rb +4 -9
- data/lib/shiny_json_logic/operations/subtraction.rb +14 -2
- data/lib/shiny_json_logic/version.rb +1 -1
- data/results/ruby.json +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29b936cfc360867d9ba05f4dbc9f0c8b952f17c6932a02b4db123fb8f9621f0b
|
|
4
|
+
data.tar.gz: 7e8d052e9dc1b88cd5fd7e76d8a87c6554d51fd611c204877617268179984d6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/badges/compat.json
CHANGED
|
@@ -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
|
-
|
|
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
|
|
14
|
-
|
|
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
|
data/results/ruby.json
CHANGED
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.
|
|
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
|