Class: PulseMeter::Sensor::Indicator

Inherits:
Base
  • Object
show all
Defined in:
lib/pulse-meter/sensor/indicator.rb

Overview

Static indicator. In fact is is just a named variable 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 Base

#annotate, #annotation, #initialize

Methods included from Mixins::Dumper

included

Constructor Details

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

Instance Method Details

#cleanupObject

Cleans up all sensor metadata in Redis



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

def cleanup
  redis.del(value_key)
  super
end

#event(value) ⇒ Object

Sets indicator value

Parameters:

  • value (Float)

    new indicator value



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

def event(value)
  redis.set(value_key, value.to_f)
end

#valueFixnum

Get indicator value

Returns:

  • (Fixnum)

    indicator value or zero unless it was initialized



20
21
22
23
# File 'lib/pulse-meter/sensor/indicator.rb', line 20

def value
  val = redis.get(value_key)
  val.nil? ? 0 : val.to_f
end

#value_keyString

Gets redis key by which counter value is stored

Returns:

  • (String)


27
28
29
# File 'lib/pulse-meter/sensor/indicator.rb', line 27

def value_key
  @value_key ||= "pulse_meter:value:#{name}"
end