Class: ArrayLogic::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/array_logic/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ruleObject

Returns the value of attribute rule.



3
4
5
# File 'lib/array_logic/rule.rb', line 3

def rule
  @rule
end

#thing_idsObject (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

#thingsObject (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_combinationsObject



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_ruleObject



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_combinationsObject



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_usedObject



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

Returns:

  • (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