Class: Arelastic::Sorts::Field
- Inherits:
-
Sort
- Object
- Nodes::Node
- Sort
- Arelastic::Sorts::Field
- Defined in:
- lib/arelastic/sorts/field.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #as_elastic ⇒ Object
-
#initialize(field, extra_options = nil) ⇒ Field
constructor
Field.new(‘price’).as_elastic => ‘price’.
- #ordering ⇒ Object
- #reverse ⇒ Object
Methods inherited from Nodes::Node
#==, #convert_to_elastic, #read_option!
Methods included from Arities::Binary
Methods included from Arities::Polyadic
Methods included from Arities::Unary
Constructor Details
#initialize(field, extra_options = nil) ⇒ Field
Field.new(‘price’).as_elastic
=> 'price'
Field.new(‘price’ => ‘asc’).as_elastic
=> {'price' => 'asc'}
Field.new(‘price’, ‘order’ => ‘asc’).as_elastic
=> {'price' => {'order', 'asc'}}
Field.new(=> ‘asc’, => ‘_last’).as_elastic
=> {'price' => {'order' => 'asc', 'missing' => '_last'}}
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/arelastic/sorts/field.rb', line 18 def initialize(field, = nil) if field.is_a?(Hash) @field, @options = field.first.to_a if @options = (@options.is_a?(Hash) ? @options : {'order' => @options}).update() end else @field = field @options = end end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/arelastic/sorts/field.rb', line 4 def field @field end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/arelastic/sorts/field.rb', line 4 def @options end |
Instance Method Details
#as_elastic ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/arelastic/sorts/field.rb', line 44 def as_elastic if {field => } else field end end |
#ordering ⇒ Object
40 41 42 |
# File 'lib/arelastic/sorts/field.rb', line 40 def ordering (.is_a?(Hash) ? ['order'] : ).to_s end |
#reverse ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/arelastic/sorts/field.rb', line 30 def reverse reverse_order = ordering == 'desc' ? 'asc' : 'desc' if .is_a?(Hash) Arelastic::Sorts::Field.new(field, .merge('order' => reverse_order)) else Arelastic::Sorts::Field.new(field => reverse_order) end end |