Class: Axiom::Relation::Operation::Sorted
- Inherits:
-
Axiom::Relation
- Object
- Axiom::Relation
- Axiom::Relation::Operation::Sorted
- Includes:
- Unary
- Defined in:
- lib/axiom/relation/operation/sorted.rb,
lib/axiom/relation/operation/sorted/direction.rb,
lib/axiom/relation/operation/sorted/direction_set.rb
Overview
A class representing a sorted relation
Direct Known Subclasses
Defined Under Namespace
Modules: Methods Classes: Ascending, Descending, Direction, DirectionSet
Instance Attribute Summary collapse
-
#directions ⇒ Operation::Sorted::DirectionSet
readonly
private
The relation sort order.
Attributes included from Operation::Unary
Attributes inherited from Axiom::Relation
Class Method Summary collapse
-
.new(operand, directions) ⇒ Sorted
Instantiate a new Sorted.
Instance Method Summary collapse
-
#delete(other) ⇒ Sorted
Delete a relation from the Sorted.
-
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set.
-
#initialize(operand, directions) ⇒ undefined
constructor
private
Initialize an Sorted.
-
#insert(other) ⇒ Sorted
Insert a relation into the Sorted.
Methods inherited from Axiom::Relation
#==, #[], #empty?, #include?, #materialize, #materialized?, #replace
Methods included from Visitable
Constructor Details
#initialize(operand, directions) ⇒ 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 an Sorted
52 53 54 55 |
# File 'lib/axiom/relation/operation/sorted.rb', line 52 def initialize(operand, directions) super(operand) @directions = directions end |
Instance Attribute Details
#directions ⇒ Operation::Sorted::DirectionSet (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 relation sort order
17 18 19 |
# File 'lib/axiom/relation/operation/sorted.rb', line 17 def directions @directions end |
Class Method Details
.new(operand, directions) ⇒ Sorted
Instantiate a new Sorted
32 33 34 35 36 37 38 39 40 |
# File 'lib/axiom/relation/operation/sorted.rb', line 32 def self.new(operand, directions) header = operand.header directions = DirectionSet.coerce(directions) do |direction| header[direction] unless direction.kind_of?(Direction) end new_directions = directions | header - directions.attributes directions = new_directions if new_directions != directions super end |
Instance Method Details
#delete(other) ⇒ Sorted
Delete a relation from the Sorted
102 103 104 105 |
# File 'lib/axiom/relation/operation/sorted.rb', line 102 def delete(other) assert_matching_directions(other, DELETED) operand.delete(other.operand).sort_by(directions) end |
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set
71 72 73 74 75 |
# File 'lib/axiom/relation/operation/sorted.rb', line 71 def each return to_enum unless block_given? directions.sort_tuples(operand).each { |tuple| yield tuple } self end |