My favorites | Sign in
Project Logo
                
Code license: MIT License
Labels: rubyonrails, plugin, logic, search, ui
Feeds:
People details
Project owners:
  cainlevy

Usually reports are generated with the restrictive assumption that all search conditions must be true. It's hard to present a user interface that lets real people create complex sentential logic. The interface must be easily visualized and understood, and must import and export well-formed strings. Ethan Pooley and I prototyped this method in 2004, and this plugin is my Ruby on Rails port.

Once the user has created a sentential logic string, you still need to do something with it. The Ruby API lets you easily parse the string into a logical tree, then either evaluate the truth of the tree or convert the tree into SQL.

For example:

phrase = UserLogic::Phrase.new(%("f" or ("t" and "t")))
phrase.true? {|atom| atom == "t"}
=> true

phrase = UserLogic::Phrase.new(%("a" or ("b" and "d")))
phrase.to_sql do |atom|
  case atom
  when 'a': 'alpha'
  when 'b': 'beta'
  when 'd': 'delta'
  end
end
=> 'alpha OR (beta AND delta)'








Hosted by Google Code