2019-12-27 19:30:23 +00:00
|
|
|
|
|
|
|
require 'namarara'
|
|
|
|
|
|
|
|
# Initialize Namarara
|
|
|
|
namarara = Namarara::Parser.new(Namarara::Lexer.new)
|
|
|
|
|
2019-12-27 19:42:56 +00:00
|
|
|
# A set of rules i want to check
|
|
|
|
# (in this example we are looking for sensitive personnal data)
|
2019-12-27 19:30:23 +00:00
|
|
|
rules = {
|
|
|
|
vulnerable_person: 'is_adult AND is_subordinate',
|
|
|
|
has_constraints: 'is_adult AND has_children',
|
|
|
|
is_child: 'NOT is_adult'
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
|
|
|
|
# A set of values i want to inject (values must be expressed as strings)
|
|
|
|
namarara.names = {
|
|
|
|
"is_adult" => 'false',
|
|
|
|
"is_subordinate" => 'true',
|
|
|
|
"has_children" => 'true'
|
|
|
|
}
|
|
|
|
|
2019-12-27 19:42:56 +00:00
|
|
|
results = rules.map { |rule, expr| [rule, namarara.parse(expr).compute] }
|
2019-12-27 19:30:23 +00:00
|
|
|
|
2019-12-27 19:42:56 +00:00
|
|
|
if results.select{ |rule, value| value }.empty?
|
2019-12-27 19:30:23 +00:00
|
|
|
puts "Perfect! Nothing to say ;-)"
|
2019-12-27 19:42:56 +00:00
|
|
|
else
|
|
|
|
puts "Warning: you are collectif sensitive personnal data !"
|
|
|
|
results.each do |rule, value|
|
|
|
|
puts "#{value ? '>>':' '} #{rule}: #{value}"
|
|
|
|
end
|
2019-12-27 19:30:23 +00:00
|
|
|
end
|