Class: Noiseless::AST::Aggregation

Inherits:
Node
  • Object
show all
Defined in:
lib/noiseless/ast/aggregation.rb

Constant Summary collapse

METRIC_TYPES =
%i[avg sum min max cardinality value_count stats extended_stats percentiles].freeze
BUCKET_TYPES =
%i[terms histogram date_histogram range date_range filter filters nested].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#to_h

Constructor Details

#initialize(name, type, field: nil, sub_aggregations: [], **options) ⇒ Aggregation

Returns a new instance of Aggregation.



11
12
13
14
15
16
17
18
# File 'lib/noiseless/ast/aggregation.rb', line 11

def initialize(name, type, field: nil, sub_aggregations: [], **options)
  super()
  @name = name.to_s
  @type = type.to_sym
  @field = field&.to_s
  @options = options
  @sub_aggregations = sub_aggregations
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'lib/noiseless/ast/aggregation.rb', line 6

def field
  @field
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/noiseless/ast/aggregation.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/noiseless/ast/aggregation.rb', line 6

def options
  @options
end

#sub_aggregationsObject (readonly)

Returns the value of attribute sub_aggregations.



6
7
8
# File 'lib/noiseless/ast/aggregation.rb', line 6

def sub_aggregations
  @sub_aggregations
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/noiseless/ast/aggregation.rb', line 6

def type
  @type
end

Instance Method Details

#add_sub_aggregation(aggregation) ⇒ Object



28
29
30
# File 'lib/noiseless/ast/aggregation.rb', line 28

def add_sub_aggregation(aggregation)
  @sub_aggregations << aggregation
end

#bucket?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/noiseless/ast/aggregation.rb', line 24

def bucket?
  BUCKET_TYPES.include?(@type)
end

#metric?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/noiseless/ast/aggregation.rb', line 20

def metric?
  METRIC_TYPES.include?(@type)
end