Class: PulseMeter::Sensor::Multi

Inherits:
Base
  • Object
show all
Includes:
Enumerable, Mixins::Utils
Defined in:
lib/pulse_meter/sensor/multi.rb

Constant Summary

Constants included from Mixins::Dumper

Mixins::Dumper::DUMP_REDIS_KEY

Instance Attribute Summary collapse

Attributes inherited from Base

#redis

Instance Method Summary collapse

Methods included from Mixins::Utils

#assert_array!, #assert_positive_integer!, #assert_ranged_float!, #camelize, #camelize_keys, #constantize, #each_subset, #parse_time, #subsets_of, #symbolize_keys, #titleize, #underscore, #uniqid

Methods inherited from Base

#annotate, #annotation, #cleanup, #command_aggregator

Methods included from Mixins::Dumper

included

Constructor Details

#initialize(name, options) ⇒ Multi

TODO restore in initializer

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# File 'lib/pulse_meter/sensor/multi.rb', line 14

def initialize(name, options)
  @name = name
  @factors = assert_array!(options, :factors)
  @sensors = PulseMeter::Sensor::Configuration.new
  @configuration_options = options[:configuration]
  raise ArgumentError, "configuration option missing" unless @configuration_options
end

Instance Attribute Details

#configuration_optionsObject (readonly)

Returns the value of attribute configuration_options.



10
11
12
# File 'lib/pulse_meter/sensor/multi.rb', line 10

def configuration_options
  @configuration_options
end

#factorsObject (readonly)

Returns the value of attribute factors.



8
9
10
# File 'lib/pulse_meter/sensor/multi.rb', line 8

def factors
  @factors
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/pulse_meter/sensor/multi.rb', line 7

def name
  @name
end

#sensorsObject (readonly)

Returns the value of attribute sensors.



9
10
11
# File 'lib/pulse_meter/sensor/multi.rb', line 9

def sensors
  @sensors
end

Instance Method Details

#eachObject



38
39
40
# File 'lib/pulse_meter/sensor/multi.rb', line 38

def each
  sensors.each {|s| yield(s)}
end

#event(factors_hash, value) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/pulse_meter/sensor/multi.rb', line 27

def event(factors_hash, value)
  ensure_valid_factors!(factors_hash)

  each_factors_combination do |combination|
    factor_values = factor_values_for_combination(combination, factors_hash)
    get_or_create_sensor(combination, factor_values) do |s|
      s.event(value)
    end
  end
end

#sensor(name) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
# File 'lib/pulse_meter/sensor/multi.rb', line 22

def sensor(name)
  raise ArgumentError, 'need a block' unless block_given?
  sensors.sensor(name){|s| yield(s)}
end

#sensor_for_factors(factor_names, factor_values) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
# File 'lib/pulse_meter/sensor/multi.rb', line 42

def sensor_for_factors(factor_names, factor_values)
  raise ArgumentError, 'need a block' unless block_given?
  sensor(get_sensor_name(factor_names, factor_values)){|s| yield(s)}
end