shiny_json_logic 0.1.9 → 0.2.0
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 +3 -0
- data/Gemfile.lock +1 -1
- data/lib/shiny_json_logic/engine.rb +2 -1
- data/lib/shiny_json_logic/numericals/with_error_handling.rb +10 -6
- data/lib/shiny_json_logic/operations/division.rb +18 -1
- data/lib/shiny_json_logic/version.rb +1 -1
- data/results/ruby.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a20fb7e281bf025ff316d3792c9bc2318690479d45e7191f9f4a816786398c2f
|
|
4
|
+
data.tar.gz: f35df94f77e3338b55f8802b482c41b033223038d778ba3dd611ce059968a42f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c64e34362fd188c4b5b32f37494e9a0449b96e030f67591e57e19e4dfdf31c3d646c0324e90ad09ffa7efb7816547141a44865482c36558d30f00f498e30fcda
|
|
7
|
+
data.tar.gz: 5b5df2b33a6651852287cbb04aa107d8a5a1145b73cae91c7df344224f26abdc3d191a8aaf0ebe447d01f79d3e2cb283c6d09a5c2b2d238dfe9af930eda6d716
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -22,7 +22,8 @@ module ShinyJsonLogic
|
|
|
22
22
|
if raw_args.is_a?(Array)
|
|
23
23
|
raw_args.map { |val| call(val, data) }
|
|
24
24
|
else
|
|
25
|
-
|
|
25
|
+
call = call(raw_args, data)
|
|
26
|
+
call.is_a?(Array) ? call : [call(raw_args, data)]
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
solve(operation, evaluated_args, data)
|
|
@@ -4,13 +4,17 @@ module ShinyJsonLogic
|
|
|
4
4
|
def safe_arithmetic(&block)
|
|
5
5
|
result = yield
|
|
6
6
|
result.tap do |res|
|
|
7
|
-
if res.to_f.nan? || res == Float::INFINITY || res == -Float::INFINITY
|
|
8
|
-
self.data["type"] = "NaN"
|
|
9
|
-
error = ShinyJsonLogic::Errors::Base.new(type: "NaN")
|
|
10
|
-
errors.push error
|
|
11
|
-
return error.id
|
|
12
|
-
end
|
|
7
|
+
handle_invalid_operand if res.to_f.nan? || res == Float::INFINITY || res == -Float::INFINITY
|
|
13
8
|
end
|
|
9
|
+
rescue TypeError
|
|
10
|
+
handle_invalid_operand
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def handle_invalid_operand
|
|
14
|
+
self.data["type"] = "NaN"
|
|
15
|
+
error = ShinyJsonLogic::Errors::Base.new(type: "NaN")
|
|
16
|
+
errors.push error
|
|
17
|
+
return error.id
|
|
14
18
|
end
|
|
15
19
|
end
|
|
16
20
|
end
|
|
@@ -9,21 +9,38 @@ module ShinyJsonLogic
|
|
|
9
9
|
|
|
10
10
|
def run
|
|
11
11
|
return handle_no_operators if rules.empty?
|
|
12
|
+
return handle_nil_operands if rules.any?(&:nil?)
|
|
13
|
+
|
|
12
14
|
safe_arithmetic do
|
|
13
15
|
self.rules = [1, *rules] if rules.size < 2
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
numberified.reduce(:/)
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
private
|
|
20
22
|
|
|
23
|
+
def handle_nil_operands
|
|
24
|
+
error = Errors::Base.new(type: "NaN")
|
|
25
|
+
self.errors << error
|
|
26
|
+
|
|
27
|
+
error.id
|
|
28
|
+
end
|
|
29
|
+
|
|
21
30
|
def handle_no_operators
|
|
22
31
|
error = Errors::Base.new(type: "Invalid Arguments")
|
|
23
32
|
self.errors << error
|
|
24
33
|
|
|
25
34
|
error.id
|
|
26
35
|
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
|
|
27
44
|
end
|
|
28
45
|
end
|
|
29
46
|
end
|
data/results/ruby.json
CHANGED