json-logic-rb 0.1.0.beta1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f6841b0bb7968ba96acb42d78d167b14c9757b66f7e76a87b474a6af22958e5
4
- data.tar.gz: 1c6a5520ce8de25ad8191542e2e0aeb3ce57846ef40d8bcd66ed0a061a5ed407
3
+ metadata.gz: 5707bf9b405fa29dd6538a189fb8651219da38a6adae5c20b83a9105e76f4ca8
4
+ data.tar.gz: 59e6be4c62e2b4bc48bca88d1c24010c896a919d4f0ad3cd06ef326b3df7b65d
5
5
  SHA512:
6
- metadata.gz: 6c988634418f03c386e0c53ccd5323b2566bf13679d81b15c7f22538b7179b3d6a49f9998520d5155fd36e249d0b809951cc164a11d0ae425a9e09e67cf56b2d
7
- data.tar.gz: 5e8e604fd9cc6cd1c927d071478db8cc4c00d6ca5bced126fba001d481998df551c766312d91aed49800495633220df85391cad88b0e6e98c235c8a9e0dc13c3
6
+ metadata.gz: 7b9b11b25711edc2956999404da117022453074ce2a23420a3a5b885859c993ec84cb553e8f55a556feacf01deff8ed90e76b154b1d5fd4122f4675c42e92b6f
7
+ data.tar.gz: b1bb6ed52e18c158b72e04fc20e42883dd3e426b937cf4be37d24cfdf7785b629f315ace39dd612dd42a0d5079c06a299463549917a4f56740991012f886f899
data/README.md CHANGED
@@ -43,7 +43,7 @@ gem install json-logic-rb
43
43
  ## Quick start
44
44
 
45
45
  ```ruby
46
- require "json-logic-rb"
46
+ require 'json_logic'
47
47
 
48
48
  rule = { "+" => [1, 2, 3] }
49
49
 
@@ -313,3 +313,9 @@ Expected output
313
313
  - Rules are **data**, not code; no Ruby eval.
314
314
  - When evaluating untrusted rules, consider adding a timeout and error handling at the call site.
315
315
  - Custom operations should be **pure** (no IO, no network, no shell).
316
+
317
+
318
+ ## Authors
319
+
320
+ - [Valeriya Petrova](https://github.com/piatrova-valeriya1999)
321
+ - [Tavrel Kate](https://github.com/tavrelkate)
@@ -2,6 +2,8 @@
2
2
 
3
3
  module JsonLogic
4
4
  module Semantics
5
+ NUMERIC_RE = /\A[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\z/.freeze
6
+
5
7
  module_function
6
8
 
7
9
  def truthy?(v)
@@ -18,8 +20,16 @@ module JsonLogic
18
20
  def falsy?(v) = !truthy?(v)
19
21
 
20
22
  def to_number(v)
21
- return v.to_f if v.is_a?(Numeric) || v.is_a?(String)
22
- v.to_s.to_f
23
+ case v
24
+ when Integer then v
25
+ when Numeric then v.to_f
26
+ when String
27
+ s = v.strip
28
+ return nil unless NUMERIC_RE.match?(s)
29
+ s =~ /[.eE]/ ? s.to_f : s.to_i
30
+ else
31
+ nil
32
+ end
23
33
  end
24
34
 
25
35
  def strict_equal(a,b)
@@ -30,12 +40,13 @@ module JsonLogic
30
40
  end
31
41
  end
32
42
 
33
- def loose_equal(a,b)
34
- if (a.is_a?(Numeric)||a.is_a?(String)) && (b.is_a?(Numeric)||b.is_a?(String))
35
- to_number(a) == to_number(b)
36
- else
37
- a == b
43
+ def loose_equal(a, b)
44
+ if (a.is_a?(Numeric) || a.is_a?(String)) && (b.is_a?(Numeric) || b.is_a?(String))
45
+ na = to_number(a)
46
+ nb = to_number(b)
47
+ return na == nb unless na.nil? || nb.nil?
38
48
  end
49
+ a == b
39
50
  end
40
51
  end
41
52
  end
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module JsonLogic; VERSION = '0.1.0.beta1'; end
3
+ module JsonLogic; VERSION = '0.1.0'; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-logic-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tavrel Kate