Class: PulseMeter::Sensor::Multi
- 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
-
#configuration_options ⇒ Object
readonly
Returns the value of attribute configuration_options.
-
#factors ⇒ Object
readonly
Returns the value of attribute factors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sensors ⇒ Object
readonly
Returns the value of attribute sensors.
Attributes inherited from Base
Instance Method Summary collapse
- #each ⇒ Object
- #event(factors_hash, value) ⇒ Object
-
#initialize(name, options) ⇒ Multi
constructor
TODO restore in initializer.
- #sensor(name) ⇒ Object
- #sensor_for_factors(factor_names, factor_values) ⇒ Object
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
Constructor Details
#initialize(name, options) ⇒ Multi
TODO restore in initializer
14 15 16 17 18 19 20 |
# File 'lib/pulse_meter/sensor/multi.rb', line 14 def initialize(name, ) @name = name @factors = assert_array!(, :factors) @sensors = PulseMeter::Sensor::Configuration.new @configuration_options = [:configuration] raise ArgumentError, "configuration option missing" unless @configuration_options end |
Instance Attribute Details
#configuration_options ⇒ Object (readonly)
Returns the value of attribute configuration_options.
10 11 12 |
# File 'lib/pulse_meter/sensor/multi.rb', line 10 def @configuration_options end |
#factors ⇒ Object (readonly)
Returns the value of attribute factors.
8 9 10 |
# File 'lib/pulse_meter/sensor/multi.rb', line 8 def factors @factors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/pulse_meter/sensor/multi.rb', line 7 def name @name end |
#sensors ⇒ Object (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
#each ⇒ Object
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
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
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 |