Class: Axiom::Algebra::Restriction
- Includes:
- Relation::Operation::Unary
- Defined in:
- lib/axiom/algebra/restriction.rb
Overview
Restrict the tuples to those that match a predicate
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- TAUTOLOGY =
Function::Proposition::Tautology.instance
Instance Attribute Summary collapse
-
#predicate ⇒ Function, #call
readonly
private
The predicate for the relation.
Attributes included from Operation::Unary
Attributes inherited from Relation
Instance Method Summary collapse
-
#delete(other) ⇒ Restriction
Delete a relation from the Restriction.
-
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set.
-
#initialize(operand, predicate) ⇒ undefined
constructor
private
Initialize a Restriction.
-
#insert(other) ⇒ Restriction
Insert a relation into the Restriction.
Methods inherited from Relation
#==, #[], #directions, #empty?, #include?, #materialize, #materialized?, new, #replace
Methods included from Visitable
Constructor Details
#initialize(operand, predicate) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Restriction
30 31 32 33 |
# File 'lib/axiom/algebra/restriction.rb', line 30 def initialize(operand, predicate) super(operand) @predicate = predicate end |
Instance Attribute Details
#predicate ⇒ Function, #call (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The predicate for the relation
18 19 20 |
# File 'lib/axiom/algebra/restriction.rb', line 18 def predicate @predicate end |
Instance Method Details
#delete(other) ⇒ Restriction
Delete a relation from the Restriction
The tuples must match the predicate to be deleted.
86 87 88 89 |
# File 'lib/axiom/algebra/restriction.rb', line 86 def delete(other) other = coerce(other) operand.delete(other.restrict(predicate)).restrict(predicate) end |
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set
49 50 51 52 53 54 55 |
# File 'lib/axiom/algebra/restriction.rb', line 49 def each return to_enum unless block_given? operand.each do |tuple| yield tuple if Function.extract_value(predicate, tuple).equal?(true) end self end |
#insert(other) ⇒ Restriction
Insert a relation into the Restriction
The tuples must match the predicate to be inserted.
69 70 71 72 |
# File 'lib/axiom/algebra/restriction.rb', line 69 def insert(other) other = coerce(other) operand.insert(other.restrict(predicate)).restrict(predicate) end |