title: Using Rules Engine
body: <p>I have the following situation - </p>
  
  <p>I have <code>Company</code> and I have <code>Incident</code>. </p>
  
  <p>A <code>Company</code> offers many services (<code>Service</code>) and hence - <code>has_and_belongs_to_many :services</code>.</p>
  
  <p>An <code>Incident</code> needs some services (<code>Service</code>) and hence - <code>has_and_belongs_to_many :services</code></p>
  
  <p>Now for a given incident I need to find all the companies that offer the services I need. I am looking to use a rules engine to do this because I have a lot more complex conditions to apply to pick the right set of companies.</p>
  
  <p>I looked into this gem called - <code>Wongi-engine</code> (github.com/ulfurinn/wongi-engine), but its too hard to wrap my head around it and write rules.</p>
  
  <p>Can you provide any pointers for me? Thanks!</p>
  
  <p>I can come up with following <code>facts</code>:</p>
  
  <pre><code>engine &lt;&lt; [ "CompanyA", "offers", "serviceA" ]
  engine &lt;&lt; [ "CompanyB", "offers", "serviceB" ]
  engine &lt;&lt; [ "CompanyA", "offers", "serviceB" ]
  engine &lt;&lt; [ "CompanyB", "offers", "serviceC" ]
  engine &lt;&lt; [ "IncidentA", "requires", "serviceC" ]
  engine &lt;&lt; [ "IncidentA", "requires", "serviceA" ]
  </code></pre>
  
  <p>EDIT:
  Also once I write these rules, how do I use Rails models in place of these strings? And are there any best practices for loading the facts into the engine in the context of a Ruby on Rails application?</p>
  
  <p>My usecase is, user selects an incident and asks for companies that can service the incident. And I need to ask the Rules engine for a list of companies that can do the trick :)</p>