Class: Elastic::Nodes::Agg::BaseMetric

Inherits:
BaseAgg show all
Defined in:
lib/elastic/nodes/agg/base_metric.rb

Direct Known Subclasses

Average, Maximum, Minimum, Stats, Sum

Instance Attribute Summary collapse

Attributes inherited from BaseAgg

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAgg

#initialize

Methods inherited from Base

#==, #traverse

Methods included from Support::Traversable

#pick_nodes, #traverse

Constructor Details

This class inherits a constructor from Elastic::Nodes::BaseAgg

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



10
11
12
# File 'lib/elastic/nodes/agg/base_metric.rb', line 10

def field
  @field
end

#missingObject

Returns the value of attribute missing.



10
11
12
# File 'lib/elastic/nodes/agg/base_metric.rb', line 10

def missing
  @missing
end

Class Method Details

.build(_name, _field, missing: nil) ⇒ Object



3
4
5
6
7
8
# File 'lib/elastic/nodes/agg/base_metric.rb', line 3

def self.build(_name, _field, missing: nil)
  super(_name).tap do |node|
    node.field = _field
    node.missing = missing
  end
end

Instance Method Details

#cloneObject



12
13
14
# File 'lib/elastic/nodes/agg/base_metric.rb', line 12

def clone
  prepare_clone super
end

#handle_result(_raw, _formatter) ⇒ Object



27
28
29
30
# File 'lib/elastic/nodes/agg/base_metric.rb', line 27

def handle_result(_raw, _formatter)
  # TODO: apply formatter to value
  Elastic::Results::Metric.new _raw['value']
end

#render(_options = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/elastic/nodes/agg/base_metric.rb', line 20

def render(_options = {})
  hash = { 'field' => @field.to_s }
  hash['missing'] = @missing if @missing

  { metric => hash }
end

#simplifyObject



16
17
18
# File 'lib/elastic/nodes/agg/base_metric.rb', line 16

def simplify
  prepare_clone super
end