没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > userlogic |
userlogic
|
0 | 0 | 0 |
贡献者 | 讨论 | 代码提交 |
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)'