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, explicit_tags = false, rate = false, rate_options = {}) ⇒ Query

Returns a new instance of Query.



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

def initialize(aggregator, metric, downsample = nil, explicit_tags = false, rate = false, rate_options = {})
  @aggregator = aggregator
  @metric = metric
  @downsample = downsample
  @rate = rate
  @rate_options = rate_options
  @tags = {}
  @filters = []
  @explicit_tags = explicit_tags
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

#explicit_tagsObject

Returns the value of attribute explicit_tags.



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

def explicit_tags
  @explicit_tags
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



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

def <<(filter)
  add_filter(filter)
end

#add_filter(filter) ⇒ Object



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

def add_filter(filter)
  filters << filter
end

#clear_filtersObject



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

def clear_filters
  filters.clear
end

#remove_filter(filter) ⇒ Object



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

def remove_filter(filter)
  filters.delete filter
end

#to_hObject



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

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

  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