Class: PulseMeter::Sensor::HashedIndicator

Inherits:
Indicator show all
Defined in:
lib/pulse-meter/sensor/hashed_indicator.rb

Overview

Static hashed indicator. In fact is is just a named hash with float value

Constant Summary

Constants included from Mixins::Dumper

Mixins::Dumper::DUMP_REDIS_KEY

Instance Attribute Summary

Attributes inherited from Base

#name, #redis

Instance Method Summary collapse

Methods inherited from Indicator

#cleanup, #value_key

Methods inherited from Base

#annotate, #annotation, #cleanup, #initialize

Methods included from Mixins::Dumper

included

Constructor Details

This class inherits a constructor from PulseMeter::Sensor::Base

Instance Method Details

#event(events) ⇒ Object

Sets indicator values

Parameters:

  • value (Hash)

    new indicator values



8
9
10
# File 'lib/pulse-meter/sensor/hashed_indicator.rb', line 8

def event(events)
  events.each_pair {|name, value| redis.hset(value_key, name, value.to_f)}
end

#valueFixnum

Get indicator values

Returns:

  • (Fixnum)

    indicator value or zero unless it was initialized



14
15
16
17
18
# File 'lib/pulse-meter/sensor/hashed_indicator.rb', line 14

def value
  redis.
    hgetall(value_key).
    inject(Hash.new(0)) {|h, (k, v)| h[k] = v.to_f; h}
end