Class: Elasticated::QueryAggregations

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Mixins::BlockEvaluation, Mixins::Clonable, Mixins::Inspectionable
Defined in:
lib/elasticated/query_aggregations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Inspectionable

#inspect, #text_for_inspect

Methods included from Mixins::BlockEvaluation

#evaluate

Methods included from Mixins::Clonable

#==, #clone

Constructor Details

#initializeQueryAggregations

Returns a new instance of QueryAggregations.



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

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)



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

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.



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

def _aggregations
  @_aggregations
end

Instance Method Details

#buildObject



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

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

#merge!(other_query_aggs) ⇒ Object



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

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

#parse(response) ⇒ Object



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

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