Class: Arrow::SortKey
- Inherits:
-
Object
- Object
- Arrow::SortKey
- Defined in:
- lib/arrow/sort-key.rb
Class Method Summary collapse
-
.resolve(target, order = nil) ⇒ Object
Ensure returning suitable SortKey.
- .try_convert(value) ⇒ Object private
Instance Method Summary collapse
-
#initialize(target, order = nil) ⇒ SortKey
constructor
Creates a new SortKey.
-
#to_s ⇒ String
The string representation of this sort key.
Constructor Details
#initialize(target) ⇒ SortKey #initialize(target, order) ⇒ SortKey
Creates a new Arrow::SortKey.
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.
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
#to_s ⇒ String
Returns The string representation of this sort key. You can use recreate Arrow::SortKey by ‘Arrow::SortKey.new(key.to_s)`.
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 |