Project

tagformula

0.0
No commit activity in last 3 years
No release in over 3 years
Match tag formulas with simple boolean operations against lists of strings. e.g. the formula "foo & ! bar" would match ['foo'], but not ['foo', 'bar']
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
~> 10.1
~> 2.14
 Project Readme

Tagformula::Parser

Match tag formulas with simple boolean operations against lists of strings. e.g. the formula "foo & ! bar" would match ['foo'], but not ['foo', 'bar']

Installation

Add this line to your application's Gemfile:

gem 'tagformula'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tagformula

Usage

Tagformula::Parser matches arrays of strings against formulas which require the presence or absence of strings in the array. Conditions can be nested (in brackets), or negated (with a !) and can be 'and' ('&') or 'or' ('|') conditions.

require 'tagformula/parser'

formula = Tagformula::Parser.parse("alpha & beta")

formula.matches?(%w[alpha beta])  # => true
formula.matches?(%w[alpha gamma]) # => false

formula = Tagformula::Parser.parse("alpha & (beta | gamma)")

formula.matches?(%w[alpha beta])  # => true
formula.matches?(%w[alpha gamma]) # => true

formula = Tagformula::Parser.parse("alpha & !beta")

formula.matches?(%w[alpha beta])  # => false
formula.matches?(%w[alpha gamma]) # => true

Operators:

expr & expr requires both expressions to be present

expr | expr requires either expression to be present

expr1 & ! expr2 requires the expr1 to be present and expr2 to be absent.

Special words:

"true" and "yes" will always match as true.

"false" and "no" will always match as false.

Contributing

  1. Fork it ( http://github.com/geoffyoungs/tagformula/fork )
  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