class Axiom::Relation::Operation::Sorted::Direction
Abstract base class for attribute sorting
Attributes
attribute[R]
The attribute to sort on
@return [Attribute]
@api private
Public Class Methods
coerce(object)
click to toggle source
Coerce an object into a Direction
@param [Attribute, Direction] object
the object to coerce
@return [Direction]
@api private
# File lib/axiom/relation/operation/sorted/direction.rb, line 108 def self.coerce(object) object.kind_of?(Direction) ? object : new(Attribute.coerce(object)) end
new(attribute)
click to toggle source
Initialize a Direction
@param [Attribute] attribute
the attribute to sort on
@return [undefined]
@api private
# File lib/axiom/relation/operation/sorted/direction.rb, line 31 def initialize(attribute) @attribute = attribute end
Public Instance Methods
call(left, right)
click to toggle source
Compare the left and right Tuple
attribute values
@example
comparison = direction.call(left, right)
@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 public
# File lib/axiom/relation/operation/sorted/direction.rb, line 65 def call(left, right) self.class.call(attribute.call(left), attribute.call(right)) end
name()
click to toggle source
Return the attribute name
@example
direction.name # => :id
@return [Symbol]
@api public
# File lib/axiom/relation/operation/sorted/direction.rb, line 43 def name attribute.name end
rename(aliases)
click to toggle source
Rename the contained attribute with the provided aliases
@example
renamed = direction.rename(aliases)
@param [Algebra::Rename::Aliases] aliases
the old and new attributes
@return [self]
if the attribute is not renamed
@return [Direction]
if the attribute is renamed
@api public
# File lib/axiom/relation/operation/sorted/direction.rb, line 83 def rename(aliases) renamed = aliases[attribute] renamed.equal?(attribute) ? self : self.class.new(renamed) end
reverse()
click to toggle source
Return the reverse Direction
@example
reversed = direction.reverse
@return [Direction]
@api public
# File lib/axiom/relation/operation/sorted/direction.rb, line 96 def reverse self.class.reverse.new(attribute) end