https://github.com/ps2/simple_logic
Boolean logic parsing and evaluation
https://github.com/ps2/simple_logic
Last synced: about 1 year ago
JSON representation
Boolean logic parsing and evaluation
- Host: GitHub
- URL: https://github.com/ps2/simple_logic
- Owner: ps2
- License: mit
- Created: 2014-05-30T18:27:21.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-02T17:23:55.000Z (almost 12 years ago)
- Last Synced: 2025-02-02T05:25:24.710Z (over 1 year ago)
- Language: Ruby
- Size: 160 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SimpleLogic
A ruby gem that parses and evaluates simple boolean statements specified as a string. Useful for evaluating user supplied business rules in your application without using ruby's eval().
[][travis]
[travis]: http://travis-ci.org/ps2/simple_logic
## Installation
Add this line to your application's Gemfile:
gem 'simple_logic'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple_logic
## Usage
```ruby
context = { hungry: true, fridge_empty: true, restaurant_nearby: true}
in_luck = SimpleLogic.eval("hungry && !fridge_empty || restaurant_nearby", context)
# => true
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request