Class: Axiom::Relation::Operation::Sorted::Direction

Inherits:
Object
  • Object
show all
Extended by:
Aliasable
Includes:
AbstractType
Defined in:
lib/axiom/relation/operation/sorted/direction.rb

Overview

Abstract base class for attribute sorting

Direct Known Subclasses

Ascending, Descending

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Aliasable

inheritable_alias

Constructor Details

#initialize(attribute) ⇒ 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 Direction

Parameters:

  • attribute (Attribute)

    the attribute to sort on



31
32
33
# File 'lib/axiom/relation/operation/sorted/direction.rb', line 31

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeAttribute (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 attribute to sort on

Returns:



21
22
23
# File 'lib/axiom/relation/operation/sorted/direction.rb', line 21

def attribute
  @attribute
end

Class Method Details

.coerce(object) ⇒ Direction

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.

Coerce an object into a Direction

Parameters:

Returns:



108
109
110
# File 'lib/axiom/relation/operation/sorted/direction.rb', line 108

def self.coerce(object)
  object.kind_of?(Direction) ? object : new(Attribute.coerce(object))
end

Instance Method Details

#call(left, right) ⇒ -1, ...

Compare the left and right Tuple attribute values

Examples:

comparison = direction.call(left, right)

Parameters:

Returns:

  • (-1)

    returned if the left should be sorted before the right

  • (0)

    returned if the left and right are equal

  • (1)

    returned if the left should be sorted after the right



65
66
67
# File 'lib/axiom/relation/operation/sorted/direction.rb', line 65

def call(left, right)
  self.class.call(attribute.call(left), attribute.call(right))
end

#nameSymbol

Return the attribute name

Examples:

direction.name  # => :id

Returns:

  • (Symbol)


43
44
45
# File 'lib/axiom/relation/operation/sorted/direction.rb', line 43

def name
  attribute.name
end

#rename(aliases) ⇒ self, Direction

Rename the contained attribute with the provided aliases

Examples:

renamed = direction.rename(aliases)

Parameters:

Returns:

  • (self)

    if the attribute is not renamed

  • (Direction)

    if the attribute is renamed



83
84
85
86
# 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

#reverseDirection

Return the reverse Direction

Examples:

reversed = direction.reverse

Returns:



96
97
98
# File 'lib/axiom/relation/operation/sorted/direction.rb', line 96

def reverse
  self.class.reverse.new(attribute)
end