Class: Elasticated::QueryAggregations

Inherits:
Object
  • Object
show all
Includes:
BlockEvaluation, Clonable
Defined in:
lib/elasticated/query_aggregations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlockEvaluation

#evaluate

Methods included from Clonable

#==, #clone

Constructor Details

#initializeQueryAggregations

Returns a new instance of QueryAggregations.



9
10
11
# File 'lib/elasticated/query_aggregations.rb', line 9

def initialize
  self._aggregations = Array.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



44
45
46
47
48
49
50
51
52
# File 'lib/elasticated/query_aggregations.rb', line 44

def method_missing(method_name, *args, &block)
  agg_class = get_aggregation_class method_name
  if agg_class
    aggregation = agg_class.new(*args, &block)
    add_aggregation aggregation
  else
    super
  end
end

Instance Attribute Details

#_aggregationsObject

Returns the value of attribute _aggregations.



7
8
9
# File 'lib/elasticated/query_aggregations.rb', line 7

def _aggregations
  @_aggregations
end

Instance Method Details

#buildObject



13
14
15
16
17
# File 'lib/elasticated/query_aggregations.rb', line 13

def build
  _aggregations.inject({}) do |ret, aggregation|
    ret.merge aggregation.name => aggregation.build
  end
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/elasticated/query_aggregations.rb', line 33

def empty?
  _aggregations.empty?
end

#merge!(other_query_aggs) ⇒ Object



27
28
29
30
31
# File 'lib/elasticated/query_aggregations.rb', line 27

def merge! other_query_aggs
  other_query_aggs._aggregations.each do |other_aggregation|
    add_aggregation other_aggregation
  end
end

#parse(response) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/elasticated/query_aggregations.rb', line 19

def parse(response)
  _aggregations.inject({}) do |hash, aggregation|
    name = aggregation.name.to_s
    original_name = aggregation.original_name.to_s
    hash.merge original_name => aggregation.parse(response[name])
  end
end