🟢 Stable | A library that can parses boolean expressions, builds an binary expression tree and evalue given a set of values
Go to file
2019-12-21 16:55:15 +01:00
bin Update project architecture 2017-09-12 15:32:50 +02:00
exe Change method option for CLI 2017-09-21 10:11:15 +02:00
lib Clean unit tests 2019-12-21 16:55:15 +01:00
spec Clean unit tests 2019-12-21 16:55:15 +01:00
.gitignore Update project architecture 2017-09-12 15:32:50 +02:00
.rubocop.yml Add spec with simple expr for all operators 2017-09-14 10:50:10 +02:00
.ruby-version Force ruby version 2017-11-18 16:41:52 +01:00
.tool-versions Clean unit tests 2019-12-21 16:55:15 +01:00
.travis.yml Update project architecture 2017-09-12 15:32:50 +02:00
demo.rb Clean unit tests 2019-12-21 16:55:15 +01:00
Gemfile Clean unit tests 2019-12-21 16:55:15 +01:00
LICENSE.txt Update project architecture 2017-09-12 15:32:50 +02:00
mm2ep_depend.gemspec Clean unit tests 2019-12-21 16:55:15 +01:00
Rakefile Enable rubocop 2017-09-20 10:46:17 +02:00
README.md Clean unit tests 2019-12-21 16:55:15 +01:00
rule-adult-with-child.yaml Clean unit tests 2019-12-21 16:55:15 +01:00
TODO.md Add TODO 2017-09-20 10:51:18 +02:00

Namarara

Namarara is a library that parses boolean expressions, builds an binary expression tree.

Namare can also evalutes a result from a set of values corresponding the variables used within the boolean expression.

  1. binary expression and computes a boolean result from this AST.

Installation

Add this line to your application's Gemfile:

gem 'mm2ep_depend'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mm2ep_depend

Usage

Evaluate a single expression

# Initialize Namarara
namarara = Namarara.new

# Build the binary expression tree (BET)
namarara_bet = namarara.parse('this AND (that OR other) AND something_else')

# Prepare variables 
variables = {
  this: true,
  that: false,
  other: false,
  something_else: true
}

# Compute tree with variables
result = namarara_bet.compute(variables)

Evaluating a set of rules

# Initialize Namarara
namarara = Namarara::Parser.new(Namarara::Lexer.new)

# A set of rules i want to check
rules = [
    {name: 'vulnetable_person', expr: 'is_adult AND is_subordinate'},
    {name: 'has_constraints', expr: 'is_adult AND has_children' },
    {name: 'is_child', expr: 'NOT is_adult'}
    # ...
]

# A set of values i want to inject (values can come from HTTP or from database
# as long as they are expressed as strings)
namarara.names = {
    "is_adult" => 'false', 
    "is_subordinate" => 'true',
    "has_children" => 'true'
}

rules.map do |rule|
    namarara_bet = namarara.parse(rule)
    result = namarara_bet.compute
    if result then
        warnings << "Rule #{rule} is true"
    end
end

if not warnings.empty?
puts "Attention: vous collectez des DCP de personnes vulnerables"
puts warnings.join("\n")
else
puts "Rien à dire :-)"
end

TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mm2ep_depend.

## License

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