Build rules and execute them in ruby. See https://jsonlogic.com
Install the gem and add to the application's Gemfile by executing:
$ bundle add json_logic_ruby
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install json_logic_ruby
RULE = <<~JSON
{ "and" : [
{">=" : [ { "var" : "length" }, 15 ]},
{">=" : [ { "var" : "size" }, 50 ]}
] }
JSON
DATA = JSON.parse('{ "length": 20, "size": 49 }')
logic = JsonLogic::Evaluator.new
logic.apply(JSON.parse(RULE), DATA)
logic = JsonLogic::Evaluator.new
res = logic.extract_vars(JSON.parse(RULE))
puts res
# will print -> ["length", "size"]
logic = JsonLogic::Evaluator.new
logic.apply(JSON.parse(RULE), DATA)
puts logic.tracker.report
# will print
# LOGIC: 'and', RESULT = false
# DATA: 'length' data:20 >= expected:15, RESULT = true
# DATA: 'size' data:49 >= expected:50, RESULT = false
After checking out the repo, run bundle install
to install dependencies.
Please see CONTRIBUTING.md.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Json::Logic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.