Sha256: ab0cfb66ba3a9a9d06a00e57046e06d932b22e5ed441d8715ee4ac3472fa7cc7

Contents?: true

Size: 923 Bytes

Versions: 2

Compression:

Stored size: 923 Bytes

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
array_logic-0.0.2 README.rdoc
array_logic-0.0.1 README.rdoc