Class: Logica::Predicates::Compounds::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/logica/predicates/compounds/base.rb

Direct Known Subclasses

AtLeast, Conjunction, Disjunction

Constant Summary

Constants inherited from Base

Base::ACCEPTOR_TYPE_ID

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#and, #and_not, #disjoint_with?, #exhaustive_with?, #generalization_of?, #generalization_of_negation_of?, #generalization_of_other?, #iff, #implies, #method_missing, #negated, #or, #or_not, #partially_applied_with, #portion_satisfied_by, predicate_factory, #remainder_unsatisfied_by, #respond_to_missing?, #specialization_of?, #to_method, #to_proc, #to_s, #unsatisfied_by?, #xor

Methods included from ComparableByState

#==, #hash, #state

Constructor Details

#initialize(predicates) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/logica/predicates/compounds/base.rb', line 15

def initialize(predicates)
  @predicates = predicates
  validate_composability
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Logica::Predicates::Base

Instance Attribute Details

#predicatesObject (readonly)

Returns the value of attribute predicates.



5
6
7
# File 'lib/logica/predicates/compounds/base.rb', line 5

def predicates
  @predicates
end

Class Method Details

.new_from_list(predicates) ⇒ Object



11
12
13
# File 'lib/logica/predicates/compounds/base.rb', line 11

def self.new_from_list(predicates)
  predicates.reduce(internal_binary_operation) || neutral_element
end

.new_from_pair(first_predicate, second_predicate) ⇒ Object



7
8
9
# File 'lib/logica/predicates/compounds/base.rb', line 7

def self.new_from_pair(first_predicate, second_predicate)
  new([first_predicate]).with_extra_predicate_last(second_predicate)
end

Instance Method Details

#arityObject



33
34
35
# File 'lib/logica/predicates/compounds/base.rb', line 33

def arity
  predicates.first.arity
end

#name_and_attributesObject



37
38
39
# File 'lib/logica/predicates/compounds/base.rb', line 37

def name_and_attributes
  "#{name}(#{attributes_string})"
end

#with_extra_predicate_last(extra_predicate) ⇒ Object



27
28
29
30
31
# File 'lib/logica/predicates/compounds/base.rb', line 27

def with_extra_predicate_last(extra_predicate)
  with_extra_predicate(extra_predicate) do |subsumed, extra|
    predicates - subsumed + [extra]
  end
end

#with_extra_predicates(extra_predicates) ⇒ Object



20
21
22
23
24
25
# File 'lib/logica/predicates/compounds/base.rb', line 20

def with_extra_predicates(extra_predicates)
  extra_predicates.reduce(self) do |compound, extra_predicate|
    return compound if compound == absorbing_element
    compound.with_extra_predicate_last(extra_predicate)
  end
end

#without(predicate_or_predicates, options = {}) ⇒ Object



41
42
43
# File 'lib/logica/predicates/compounds/base.rb', line 41

def without(predicate_or_predicates, options = {})
  without_predicates([predicate_or_predicates].flatten(1), options)
end