Class: Warped::Sort::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/warped/api/sort/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sort, direction) ⇒ Value

Returns a new instance of Value.

Parameters:

  • sort (Warped::Sort)

    The sort object

  • direction (String)

    The sort direction.



14
15
16
17
# File 'lib/warped/api/sort/value.rb', line 14

def initialize(sort, direction)
  @sort = sort
  @direction = direction
end

Instance Attribute Details

#sortObject (readonly)

Returns the value of attribute sort.



8
9
10
# File 'lib/warped/api/sort/value.rb', line 8

def sort
  @sort
end

Instance Method Details

#asc?Boolean

Returns Whether the sort is ascending.

Returns:

  • (Boolean)

    Whether the sort is ascending.



30
31
32
# File 'lib/warped/api/sort/value.rb', line 30

def asc?
  %w[asc asc_nulls_first asc_nulls_last].include?(direction)
end

#desc?Boolean

Returns Whether the sort is descending.

Returns:

  • (Boolean)

    Whether the sort is descending.



35
36
37
# File 'lib/warped/api/sort/value.rb', line 35

def desc?
  %w[desc desc_nulls_first desc_nulls_last].include?(direction)
end

#directionString

Returns The sort direction.

Returns:

  • (String)

    The sort direction.



20
21
22
# File 'lib/warped/api/sort/value.rb', line 20

def direction
  sort.direction!(@direction)
end

#opposite_directionString

Returns The opposite sort direction.

Returns:

  • (String)

    The opposite sort direction.



25
26
27
# File 'lib/warped/api/sort/value.rb', line 25

def opposite_direction
  sort.opposite_direction(direction)
end