Class: ElasticsearchDslBuilder::DSL::Search::Sort
- Inherits:
-
Object
- Object
- ElasticsearchDslBuilder::DSL::Search::Sort
- Defined in:
- lib/elasticsearch_dsl_builder/dsl/search/sort.rb
Overview
Wraps the ‘sort` part of a search definition
Instance Method Summary collapse
-
#by(name, direction = nil) ⇒ Object
DSL method to specify sorting item.
-
#initialize ⇒ Sort
constructor
A new instance of Sort.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Sort
Returns a new instance of Sort.
7 8 9 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/sort.rb', line 7 def initialize @value ||= [] end |
Instance Method Details
#by(name, direction = nil) ⇒ Object
DSL method to specify sorting item
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/sort.rb', line 12 def by(name, direction = nil) raise ArgumentError, 'name must be non empty String' unless name.instance_of?(String) && !name.empty? direction_valid = direction.nil? || (direction.instance_of?(String) && !direction.empty? && ['asc', 'desc'].include?(direction.downcase)) unless direction.nil? raise ArgumentError, 'direction must be non empty String' unless direction_valid end @value << (direction ? { name => direction } : name) self end |
#to_hash ⇒ Object
24 25 26 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/sort.rb', line 24 def to_hash @value.flatten end |