Class: Elasticated::QueryAggregations

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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.



12
13
14
# File 'lib/elasticated/query_aggregations.rb', line 12

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)



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

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.



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

def _aggregations
  @_aggregations
end

Instance Method Details

#buildObject



16
17
18
19
20
# File 'lib/elasticated/query_aggregations.rb', line 16

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

#merge!(other_query_aggs) ⇒ Object



30
31
32
33
34
# File 'lib/elasticated/query_aggregations.rb', line 30

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

#parse(response) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/elasticated/query_aggregations.rb', line 22

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