Class: Arrow::SortKey

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/sort-key.rb,
lib/arrow/jruby/sort-key.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ SortKey #initialize(target, order) ⇒ SortKey

Creates a new Arrow::SortKey.

Overloads:

  • #initialize(target) ⇒ SortKey

    Examples:

    String without the leading order mark

    key = Arrow::SortKey.new("count")
    key.target # => "count"
    key.order  # => Arrow::SortOrder::ASCENDING

    String with the “+” leading order mark

    key = Arrow::SortKey.new("+count")
    key.target # => "count"
    key.order  # => Arrow::SortOrder::ASCENDING

    String with the “-” leading order mark

    key = Arrow::SortKey.new("-count")
    key.target # => "count"
    key.order  # => Arrow::SortOrder::DESCENDING

    Symbol that starts with “-”

    key = Arrow::SortKey.new(:"-count")
    key.target # => "-count"
    key.order  # => Arrow::SortOrder::ASCENDING
  • #initialize(target, order) ⇒ SortKey

    Examples:

    No leading order mark processing

    key = Arrow::SortKey.new("-count", :ascending)
    key.target # => "-count"
    key.order  # => Arrow::SortOrder::ASCENDING

    Order by abbreviated target with Symbol

    key = Arrow::SortKey.new("count", :desc)
    key.target # => "count"
    key.order  # => Arrow::SortOrder::DESCENDING

    Order by String

    key = Arrow::SortKey.new("count", "descending")
    key.target # => "count"
    key.order  # => Arrow::SortOrder::DESCENDING

    Order by Arrow::SortOrder

    key = Arrow::SortKey.new("count", Arrow::SortOrder::DESCENDING)
    key.target # => "count"
    key.order  # => Arrow::SortOrder::DESCENDING

Since:

  • 4.0.0



142
143
144
145
146
# File 'lib/arrow/sort-key.rb', line 142

def initialize(target, order=nil)
  target, order = normalize_target(target, order)
  order = normalize_order(order) || :ascending
  initialize_raw(target, order)
end

Class Method Details

.resolve(sort_key) ⇒ Arrow::SortKey .resolve(target) ⇒ Arrow::SortKey .resolve(target, order) ⇒ Arrow::SortKey

Ensure returning suitable Arrow::SortKey.

Overloads:

  • .resolve(sort_key) ⇒ Arrow::SortKey

    Returns the given sort key itself. This is convenient to use this method as Arrow::SortKey converter.

  • .resolve(target) ⇒ Arrow::SortKey

    Creates a new suitable sort key from column name or dot path with leading order mark. See #initialize for details about order mark.

  • .resolve(target, order) ⇒ Arrow::SortKey

    Creates a new suitable sort key from column name or dot path without leading order mark and order. See #initialize for details.

Since:

  • 4.0.0



49
50
51
52
# File 'lib/arrow/sort-key.rb', line 49

def resolve(target, order=nil)
  return target if target.is_a?(self)
  new(target, order)
end

.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.



55
56
57
58
59
60
61
62
# File 'lib/arrow/sort-key.rb', line 55

def try_convert(value)
  case value
  when Symbol, String
    new(value.to_s, :ascending)
  else
    nil
  end
end

Instance Method Details

#nameObject

For backward compatibility



167
# File 'lib/arrow/sort-key.rb', line 167

alias_method :name, :target

#targetObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/arrow/jruby/sort-key.rb', line 20

def target
  raise NotImplementedError
end

#to_sString

Returns The string representation of this sort key. You can use recreate Arrow::SortKey by ‘Arrow::SortKey.new(key.to_s)`.

Examples:

Recreate Arrow::SortKey

key = Arrow::SortKey.new("-count")
key.to_s # => "-count"
key == Arrow::SortKey.new(key.to_s) # => true

Since:

  • 4.0.0



158
159
160
161
162
163
164
# File 'lib/arrow/sort-key.rb', line 158

def to_s
  if order == SortOrder::ASCENDING
    "+#{target}"
  else
    "-#{target}"
  end
end