json_logic 0.0.1 → 0.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
  SHA1:
3
- metadata.gz: 9a3d1616e7b6514b06d92e2b66f809e36874c158
4
- data.tar.gz: ef04c6007521f3aafb04867f844eb20d01f7949d
3
+ metadata.gz: d703a82274651845fd543ed444107612bbc93cf5
4
+ data.tar.gz: 434db11c0888e5680d00a2b90fb5171a2ad10927
5
5
  SHA512:
6
- metadata.gz: 3ae646fd4735f083c065739c7bc7d2914bf4c148904c8140dce5ce96bdb76b99595fe102f1781183138626ace75a8b1f32c8a1786647c3588057d33133f1b6a6
7
- data.tar.gz: 464ca36d6a8d559f7eb5725d9f2b520a6db23f36601db3436305ee2ce082f4954e3a8f5055ad216dd57ce0bfdd335e682ae60ab772105cf20b5124d704f032e7
6
+ metadata.gz: 51b5633809a496a26546fe5407b4fa919e591dd66ee153ffcfe9989ff39e2732f4eb0c508c497575203a4a7e2f1809cb672cde0943e91713d2f3e5aab21ddfa4
7
+ data.tar.gz: be43a7e24f84fb74226d401ccd33bd27a4fee29e6414906d11ab286801da5d2dec5c3ad333e3a281185d8a5ae19d5c0084c56b161ebd2e581abdcfb828a275cf
@@ -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'
@@ -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) # pass-thru
8
- operator, values = logic.first # unwrap single-key hash
9
- values = [values] unless values.is_a?(Array) # syntactic sugar
10
- values.map! { |value| apply(value, data) } # recursion step
11
- values.flatten!(1) if values.size == 1 # [['A']] => ['A']
12
- Operation.perform(operator, values, data || {}) # perform operation
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
 
@@ -1,3 +1,3 @@
1
1
  module JSONLogic
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1'
3
3
  end
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.0.1
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-02 00:00:00.000000000 Z
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: See http://jsonlogic.com
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: '0'
90
+ version: '2.3'
90
91
  required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  requirements:
92
93
  - - ">="