Skip to content

Commit bc6af33

Browse files
author
volodymyr_stashchenk
committed
fix: Readme
1 parent 1f4c42e commit bc6af33

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# JsonLogic
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem.
4-
Put your Ruby code in the file `lib/json_logic`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
Build rules and execute them in ruby. See https://jsonlogic.com
54

65

76
## Installation
@@ -15,41 +14,45 @@ If bundler is not being used to manage dependencies, install the gem by executin
1514
$ gem install json_logic
1615

1716
## Usage
17+
#### Run json-logic:
18+
1819
```ruby
1920
RULE = <<~JSON
2021
{ "and" : [
21-
{">=" : [ { "var" : "age" }, 50 ]},
22-
{">=" : [ { "var" : "bmi" }, 50 ]}
22+
{">=" : [ { "var" : "length" }, 15 ]},
23+
{">=" : [ { "var" : "size" }, 50 ]}
2324
] }
2425
JSON
2526

26-
DATA = JSON.parse('{ "age" : 51, "bmi" : 49}')
27+
DATA = JSON.parse('{ "length": 20, "size": 49 }')
2728

2829
logic = JsonLogic::Evaluator.new
29-
res = logic.apply(JSON.parse(RULE), DATA)
30-
puts "Criteria eligible: #{res}"
30+
logic.apply(JSON.parse(RULE), DATA)
31+
```
32+
##### Get all variables used in a rule
3133

32-
# extract all variables used in criteria
34+
```ruby
35+
logic = JsonLogic::Evaluator.new
3336
res = logic.extract_vars(JSON.parse(RULE))
34-
puts "Variables used in criteria: #{res}"
37+
puts res
3538

36-
# will print
37-
#
38-
# Variables used in criteria: ["age", "bmi"]
39+
# will print -> ["length", "size"]
40+
```
41+
42+
##### Track report of all operations
43+
```ruby
44+
logic = JsonLogic::Evaluator.new
45+
logic.apply(JSON.parse(RULE), DATA)
3946

40-
# output report of all operations
4147
puts logic.tracker.report
4248

4349
# will print
44-
#
45-
# Criteria eligible: false
4650
# LOGIC: 'and', RESULT = false
47-
# DATA: 'age' data:51 >= expected:50, RESULT = true
48-
# DATA: 'bmi' data:49 >= expected:50, RESULT = false
51+
# DATA: 'length' data:20 >= expected:15, RESULT = true
52+
# DATA: 'size' data:49 >= expected:50, RESULT = false
4953
```
5054

5155

52-
5356
## Development
5457

5558
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -58,12 +61,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
5861

5962
## Contributing
6063

61-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/json-logic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/json-logic/blob/master/CODE_OF_CONDUCT.md).
64+
Bug reports and pull requests are welcome on GitHub at https://github.com/useful-libs/json-logic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/useful-libs/json-logic/blob/main/CODE_OF_CONDUCT.md).
6265

6366
## License
6467

6568
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
6669

6770
## Code of Conduct
6871

69-
Everyone interacting in the Json::Logic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/json-logic/blob/master/CODE_OF_CONDUCT.md).
72+
Everyone interacting in the Json::Logic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/useful-libs/json-logic/blob/master/CODE_OF_CONDUCT.md).

0 commit comments

Comments
 (0)