alvesdan / query_engine

Hash matches gem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QueryEngine

You can test if a hash matches a query:

query = {
  '$or' => [
    { age: { '$gt' => 18 } },
    { role: { '$any' => ['Developer', 'Engineer'] } }
  ]
}

john = { age: 17, role: 'Student' }
jack = { age: 22, role: 'Developer' }
lisa = { age: 23, role: 'Marketing' }

QueryEngine::Matchable.matches?(john, query) #=> false
QueryEngine::Matchable.matches?(jack, query) #=> true
QueryEngine::Matchable.matches?(lisa, query) #=> true

Check out the specs for more examples.

About

Hash matches gem.

License:MIT License


Languages

Language:Ruby 100.0%