Class: Slingshot::Search::Sort

Inherits:
Object
  • Object
show all
Defined in:
lib/slingshot/search/sort.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Sort

Returns a new instance of Sort.



5
6
7
8
# File 'lib/slingshot/search/sort.rb', line 5

def initialize(&block)
  @value = []
  self.instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/slingshot/search/sort.rb', line 15

def method_missing(id, *args, &block)
  case arg = args.shift
    when String, Symbol, Hash then @value << { id => arg }
    else @value << id
  end
  self
end

Instance Method Details

#field(name, direction = nil) ⇒ Object



10
11
12
13
# File 'lib/slingshot/search/sort.rb', line 10

def field(name, direction=nil)
  @value << ( direction ? { name => direction } : name )
  self
end

#to_jsonObject



23
24
25
# File 'lib/slingshot/search/sort.rb', line 23

def to_json
  @value.to_json
end