json_logic 0.0.1 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/json_logic.gemspec +3 -1
- data/lib/json_logic.rb +10 -6
- data/lib/json_logic/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d703a82274651845fd543ed444107612bbc93cf5
|
4
|
+
data.tar.gz: 434db11c0888e5680d00a2b90fb5171a2ad10927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51b5633809a496a26546fe5407b4fa919e591dd66ee153ffcfe9989ff39e2732f4eb0c508c497575203a4a7e2f1809cb672cde0943e91713d2f3e5aab21ddfa4
|
7
|
+
data.tar.gz: be43a7e24f84fb74226d401ccd33bd27a4fee29e6414906d11ab286801da5d2dec5c3ad333e3a281185d8a5ae19d5c0084c56b161ebd2e581abdcfb828a275cf
|
data/json_logic.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['Kenneth.Geerts@gmail.com']
|
11
11
|
spec.homepage = 'http://jsonlogic.com'
|
12
12
|
spec.summary = 'Build complex rules, serialize them as JSON, and execute them in ruby'
|
13
|
-
spec.description = 'See http://jsonlogic.com'
|
13
|
+
spec.description = 'Build complex rules, serialize them as JSON, and execute them in ruby. See http://jsonlogic.com'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
end
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 2.3'
|
22
|
+
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
22
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
25
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
data/lib/json_logic.rb
CHANGED
@@ -4,12 +4,16 @@ require 'json_logic/operation'
|
|
4
4
|
|
5
5
|
module JSONLogic
|
6
6
|
def self.apply(logic, data)
|
7
|
-
return logic unless logic.is_a?(Hash)
|
8
|
-
operator, values = logic.first
|
9
|
-
values = [values] unless values.is_a?(Array)
|
10
|
-
values.map
|
11
|
-
|
12
|
-
Operation.perform(operator,
|
7
|
+
return logic unless logic.is_a?(Hash) # pass-thru
|
8
|
+
operator, values = logic.first # unwrap single-key hash
|
9
|
+
values = [values] unless values.is_a?(Array) # syntactic sugar
|
10
|
+
new_vals = values.map { |value| apply(value, data) } # recursion step
|
11
|
+
new_vals.flatten!(1) if new_vals.size == 1 # [['A']] => ['A']
|
12
|
+
Operation.perform(operator, new_vals, data || {}) # perform operation
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.filter(logic, data)
|
16
|
+
data.select { |d| apply(logic, d) }
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
data/lib/json_logic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Geerts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description:
|
55
|
+
description: Build complex rules, serialize them as JSON, and execute them in ruby.
|
56
|
+
See http://jsonlogic.com
|
56
57
|
email:
|
57
58
|
- Kenneth.Geerts@gmail.com
|
58
59
|
executables: []
|
@@ -86,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
87
|
requirements:
|
87
88
|
- - ">="
|
88
89
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
+
version: '2.3'
|
90
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
92
|
requirements:
|
92
93
|
- - ">="
|