Class: Arrow::SortOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/sort-options.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*sort_keys) ⇒ SortOptions

Returns a new instance of SortOptions.

Examples:

No initial sort keys

options = Arrow::SortOptions.new
options.sort_keys # => []

String sort keys

options = Arrow::SortOptions.new("count", "-age")
options.sort_keys.collect(&:to_s) # => ["+count", "-age"]

Symbol sort keys

options = Arrow::SortOptions.new(:count, :age)
options.sort_keys.collect(&:to_s) # => ["+count", "+age"]

Mixed sort keys

options = Arrow::SortOptions.new(:count, "-age")
options.sort_keys.collect(&:to_s) # => ["+count", "-age"]

Parameters:

Since:

  • 4.0.0



59
60
61
62
63
64
# File 'lib/arrow/sort-options.rb', line 59

def initialize(*sort_keys)
  initialize_raw
  sort_keys.each do |sort_key|
    add_sort_key(sort_key)
  end
end

Class Method Details

.try_convert(value) ⇒ Object

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.



22
23
24
25
26
27
28
29
30
31
# File 'lib/arrow/sort-options.rb', line 22

def try_convert(value)
  case value
  when Symbol, String
    new(value)
  when ::Array
    new(*value)
  else
    nil
  end
end

Instance Method Details

#add_sort_key(key) ⇒ void #add_sort_key(target) ⇒ void #add_sort_key(target, order) ⇒ void

This method returns an undefined value.

Add a sort key.

Overloads:

  • #add_sort_key(key) ⇒ void

    Examples:

    Add a key to sort by “price” column in descending order

    options = Arrow::SortOptions.new
    options.add_sort_key(Arrow::SortKey.new(:price, :descending))
    options.sort_keys.collect(&:to_s) # => ["-price"]

    Parameters:

  • #add_sort_key(target) ⇒ void

    Examples:

    Add a key to sort by “price” column in descending order

    options = Arrow::SortOptions.new
    options.add_sort_key("-price")
    options.sort_keys.collect(&:to_s) # => ["-price"]

    Parameters:

    • target (Symbol, String)

      The sort key name or dot path to be added. See also Arrow::SortKey#initialize for the leading order mark for ‘String` target.

  • #add_sort_key(target, order) ⇒ void

    Examples:

    Add a key to sort by “price” column in descending order

    options = Arrow::SortOptions.new
    options.add_sort_key("price", :desc)
    options.sort_keys.collect(&:to_s) # => ["-price"]

    Parameters:

    • target (Symbol, String)

      The sort key name or dot path.

    • order (Symbol, String, Arrow::SortOrder)

      The sort order. See Arrow::SortKey#initialize for details.

Since:

  • 4.0.0



105
106
107
# File 'lib/arrow/sort-options.rb', line 105

def add_sort_key(target, order=nil)
  add_sort_key_raw(SortKey.resolve(target, order))
end

#add_sort_key_rawObject

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.



67
# File 'lib/arrow/sort-options.rb', line 67

alias_method :add_sort_key_raw, :add_sort_key