Class: Elastic::Results::Aggregations

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elastic/results/aggregations.rb

Direct Known Subclasses

Bucket

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Traversable

#pick_nodes

Constructor Details

#initialize(_aggs) ⇒ Aggregations

Returns a new instance of Aggregations.



7
8
9
# File 'lib/elastic/results/aggregations.rb', line 7

def initialize(_aggs)
  @aggs = _aggs
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/elastic/results/aggregations.rb', line 5

def key
  @key
end

Instance Method Details

#[](_key) ⇒ Object



11
12
13
# File 'lib/elastic/results/aggregations.rb', line 11

def [](_key)
  @aggs[_key.to_sym].try(:as_value)
end

#as_valueObject



19
20
21
22
# File 'lib/elastic/results/aggregations.rb', line 19

def as_value
  # TODO: return aggregation value if configured as single bucket
  self
end

#each(&_block) ⇒ Object



15
16
17
# File 'lib/elastic/results/aggregations.rb', line 15

def each(&_block)
  @aggs.each(&_block)
end

#traverse(&_block) ⇒ Object



24
25
26
27
# File 'lib/elastic/results/aggregations.rb', line 24

def traverse(&_block)
  super
  @aggs.each_value { |a| a.traverse(&_block) }
end