Sha256: 346b9db45ce8e00c50e2635b18896076bbd1554f934a0782686986167d3445ce
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
== array_logic A system that allows me to define the logic for comparing arrays. The logic for an active record model Answer, looks like this: a1 = Answer.find(1) a2 = Answer.find(2) .... a5 = Answer.find(5) rule_one.rule = "(a1 and a2) or (a3 and a4)" rule_two.rule = "a1 and not a2" rule_three.rule = "2 in a1 a2 a3" rule_four.rule = "(2 in a1 a2 a3) and (1 in a4 a5)" rule_one rule_two rule_three rule_four [a1, a2] true false true false [a3, a4] true false false false [a1, a3, a5] false true true true The *match* and *matches* methods allow arrays to be tested against these rules: rule_two.match([a1, a2]) --> false rule_two.matches([a1, a2], [a1]) --> [[a1]] See test/array_logic/rule_test for more examples === Combinations that match Two methods allow you to determine sample combinations that match the current rule. rule = ArrayLogic::Rule.new rule.rule = 'a1 and a2' rule.combinations_that_match --> [[1,2]] rule.combinations_that_do_not_match --> [[1],[2]] To limit the number of samples presented, both only use ids used within the rule. For the example about, an array that includes [1,2] would match, and so would [1,2,3]. However, arrays that only contain 1 or 2 would not match (for example [1,3]) Run example.rb to see some more examples ruby /lib/example.rb
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
array_logic-0.0.5 | README.rdoc |
array_logic-0.0.4 | README.rdoc |
array_logic-0.0.3 | README.rdoc |