Class: Memoir::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/memoir/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregator, metric, downsample = nil, rate = false, rate_options = {}) ⇒ Query

Returns a new instance of Query.



4
5
6
7
8
9
10
11
12
# File 'lib/memoir/query.rb', line 4

def initialize(aggregator, metric, downsample = nil, rate = false, rate_options = {})
  @aggregator = aggregator
  @metric = metric
  @downsample = downsample
  @rate = rate
  @rate_options = rate_options
  @tags = {}
  @filters = []
end

Instance Attribute Details

#aggregatorObject

Returns the value of attribute aggregator.



2
3
4
# File 'lib/memoir/query.rb', line 2

def aggregator
  @aggregator
end

#downsampleObject

Returns the value of attribute downsample.



2
3
4
# File 'lib/memoir/query.rb', line 2

def downsample
  @downsample
end

#filtersObject

Returns the value of attribute filters.



2
3
4
# File 'lib/memoir/query.rb', line 2

def filters
  @filters
end

#metricObject

Returns the value of attribute metric.



2
3
4
# File 'lib/memoir/query.rb', line 2

def metric
  @metric
end

#rateObject

Returns the value of attribute rate.



2
3
4
# File 'lib/memoir/query.rb', line 2

def rate
  @rate
end

#rate_optionsObject

Returns the value of attribute rate_options.



2
3
4
# File 'lib/memoir/query.rb', line 2

def rate_options
  @rate_options
end

Instance Method Details

#<<(filter) ⇒ Object



14
15
16
# File 'lib/memoir/query.rb', line 14

def <<(filter)
  add_filter(filter)
end

#add_filter(filter) ⇒ Object



18
19
20
# File 'lib/memoir/query.rb', line 18

def add_filter(filter)
  filters << filter
end

#clear_filtersObject



26
27
28
# File 'lib/memoir/query.rb', line 26

def clear_filters
  filters.clear
end

#remove_filter(filter) ⇒ Object



22
23
24
# File 'lib/memoir/query.rb', line 22

def remove_filter(filter)
  filters.delete filter
end

#to_hObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/memoir/query.rb', line 30

def to_h
  hash = {
    'aggregator' => aggregator,
    'metric' => metric,
    'rate' => rate
  }

  hash['rateOptions'] = rate_options unless rate_options.empty?
  hash['downsample'] = downsample.to_s if downsample
  hash['filters'] = filters.map(&:to_h) unless filters.empty?

  hash
end