class Axiom::Relation::Operation::Sorted::DirectionSet
A class that represents a tuple sort order for a set of attributes
Constants
- EMPTY
Represent an empty set of directions
Private Class Methods
coerce_attribute(attribute)
click to toggle source
Coerce the attribute into a Direction
@param [Object] attribute
@return [Direction]
@api private
# File lib/axiom/relation/operation/sorted/direction_set.rb, line 19 def self.coerce_attribute(attribute) Ascending.coerce(attribute) end
Public Instance Methods
attributes()
click to toggle source
Return each attribute in an Array
@return [Array]
@api private
# File lib/axiom/relation/operation/sorted/direction_set.rb, line 57 def attributes map(&:attribute) end
rename(aliases)
click to toggle source
Rename the contained attributes with the provided aliases
@example
renamed = directions.rename(aliases)
@param [Algebra::Rename::Aliases] aliases
the old and new attributes
@return [DirectionSet]
@api public
# File lib/axiom/relation/operation/sorted/direction_set.rb, line 36 def rename(aliases) new(map { |direction| direction.rename(aliases) }) end
reverse()
click to toggle source
Reverse
the directions for each attribute
@example
reversed = directions.reverse
@return [DirectionSet]
@api public
# File lib/axiom/relation/operation/sorted/direction_set.rb, line 48 def reverse new(map(&:reverse)) end
sort_tuples(tuples)
click to toggle source
Sort the supplied tuples in the correct direction
@param [Array] tuples
the list of tuples to sort
@return [Array]
the sorted tuples
@api private
# File lib/axiom/relation/operation/sorted/direction_set.rb, line 70 def sort_tuples(tuples) tuples.to_a.sort { |left, right| cmp_tuples(left, right) } end
Private Instance Methods
cmp_tuples(left, right)
click to toggle source
Compare the attributes for each Tuple
@param [Tuple] left @param [Tuple] right
@return [-1]
returned if the left should be sorted before the right
@return [0]
returned if the left and right are equal
@return [1]
returned if the left should be sorted after the right
@api private
# File lib/axiom/relation/operation/sorted/direction_set.rb, line 91 def cmp_tuples(left, right) reduce(0) do |cmp, direction| return cmp if cmp.nonzero? direction.call(left, right) end end