Class: ArrayLogic::Rule
- Inherits:
-
Object
- Object
- ArrayLogic::Rule
- Defined in:
- lib/array_logic/rule.rb
Instance Attribute Summary collapse
-
#rule ⇒ Object
Returns the value of attribute rule.
-
#thing_ids ⇒ Object
readonly
Returns the value of attribute thing_ids.
-
#things ⇒ Object
readonly
Returns the value of attribute things.
Instance Method Summary collapse
- #block(things) ⇒ Object
- #blockers(*array_of_things) ⇒ Object
- #blocking_combinations ⇒ Object
- #check_rule ⇒ Object
-
#initialize(rule = nil) ⇒ Rule
constructor
A new instance of Rule.
- #match(things) ⇒ Object
- #matches(*array_of_things) ⇒ Object
- #matching_combinations ⇒ Object
- #object_ids_used ⇒ Object
- #rule_valid? ⇒ Boolean
Constructor Details
#initialize(rule = nil) ⇒ Rule
Returns a new instance of Rule.
6 7 8 |
# File 'lib/array_logic/rule.rb', line 6 def initialize(rule = nil) @rule = rule end |
Instance Attribute Details
#rule ⇒ Object
Returns the value of attribute rule.
3 4 5 |
# File 'lib/array_logic/rule.rb', line 3 def rule @rule end |
#thing_ids ⇒ Object (readonly)
Returns the value of attribute thing_ids.
4 5 6 |
# File 'lib/array_logic/rule.rb', line 4 def thing_ids @thing_ids end |
#things ⇒ Object (readonly)
Returns the value of attribute things.
4 5 6 |
# File 'lib/array_logic/rule.rb', line 4 def things @things end |
Instance Method Details
#block(things) ⇒ Object
24 25 26 |
# File 'lib/array_logic/rule.rb', line 24 def block(things) ! match(things) end |
#blockers(*array_of_things) ⇒ Object
14 15 16 |
# File 'lib/array_logic/rule.rb', line 14 def blockers(*array_of_things) array_of_things.delete_if{|things| match(things)} end |
#blocking_combinations ⇒ Object
44 45 46 |
# File 'lib/array_logic/rule.rb', line 44 def blocking_combinations combinations_of_identifiers_in_rule_that_pass {|c| ! match_ids(c)} end |
#check_rule ⇒ Object
48 49 50 51 |
# File 'lib/array_logic/rule.rb', line 48 def check_rule check_rule_entered check_allowed_characters end |
#match(things) ⇒ Object
18 19 20 21 22 |
# File 'lib/array_logic/rule.rb', line 18 def match(things) check_rule @things = things match_ids things.collect(&:id) end |
#matches(*array_of_things) ⇒ Object
10 11 12 |
# File 'lib/array_logic/rule.rb', line 10 def matches(*array_of_things) array_of_things.delete_if{|things| block(things)} end |
#matching_combinations ⇒ Object
40 41 42 |
# File 'lib/array_logic/rule.rb', line 40 def matching_combinations combinations_of_identifiers_in_rule_that_pass {|c| match_ids(c)} end |
#object_ids_used ⇒ Object
35 36 37 38 |
# File 'lib/array_logic/rule.rb', line 35 def object_ids_used chrs_after_first = 1..-1 @object_ids_used ||= objects_identifiers_in_rule.collect{|i| i[chrs_after_first].to_i}.uniq end |
#rule_valid? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/array_logic/rule.rb', line 28 def rule_valid? check_rule !rule.empty? rescue return false end |