Class: Wonkavision::Plugins::Aggregation::AggregationSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AggregationSpec

Returns a new instance of AggregationSpec.



8
9
10
11
12
13
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 8

def initialize(name)
  @name = name
  @measures = HashWithIndifferentAccess.new
  @aggregations = []
  @dimensions = HashWithIndifferentAccess.new
end

Instance Attribute Details

#aggregationsObject (readonly)

Returns the value of attribute aggregations.



6
7
8
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 6

def aggregations
  @aggregations
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



6
7
8
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 6

def dimensions
  @dimensions
end

#filter(&block) ⇒ Object (readonly)

Returns the value of attribute filter.



6
7
8
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 6

def filter
  @filter
end

#measuresObject (readonly)

Returns the value of attribute measures.



6
7
8
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 6

def measures
  @measures
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 6

def name
  @name
end

Instance Method Details

#aggregate_all_combinationsObject Also known as: aggregate_by_all



31
32
33
34
35
36
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 31

def aggregate_all_combinations
  dimension_names = dimensions.keys
  (1..dimension_names.length).each do |combination_size|
    dimension_names.combination(combination_size).each { |combo| aggregate_by *combo}
  end
end

#aggregate_by(*aggregation_list) ⇒ Object



27
28
29
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 27

def aggregate_by(*aggregation_list)
  self.aggregations << aggregation_list.flatten
end

#dimension(*dimension_names, &block) ⇒ Object



15
16
17
18
19
20
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 15

def dimension(*dimension_names,&block)
  options = dimension_names.extract_options! || {}
  dimension_names.flatten.each do |dim|
    @dimensions[dim] = Dimension.new(dim,options,&block)
  end
end

#matches(message) ⇒ Object



44
45
46
47
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 44

def matches(message)
  return true unless filter
  filter.arity == 0 ? filter.call : filter.call(message)
end

#measure(*measure_list) ⇒ Object



22
23
24
25
# File 'lib/wonkavision/plugins/analytics/aggregation/aggregation_spec.rb', line 22

def measure(*measure_list)
  options = measure_list.extract_options! || {}
  measure_list.flatten.each { |m| self.measures[m] = options }
end