Class: PulseMeter::Sensor::Base Abstract
- Inherits:
-
Object
- Object
- PulseMeter::Sensor::Base
- Includes:
- Mixins::Dumper
- Defined in:
- lib/pulse-meter/sensor/base.rb
Overview
This class is abstract.
Subclass and override #event to implement sensor
Constant Summary
Constants included from Mixins::Dumper
Mixins::Dumper::DUMP_REDIS_KEY
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#redis ⇒ Object
Returns Redis instance.
Instance Method Summary collapse
-
#annotate(description) ⇒ Object
Saves annotation to Redis.
-
#annotation ⇒ String
Retrieves annotation from Redis.
-
#cleanup ⇒ Object
Cleans up all sensor metadata in Redis.
- #event(value) ⇒ Object abstract
-
#initialize(name, options = {}) ⇒ Base
constructor
Initializes sensor and dumps it to redis.
Methods included from Mixins::Dumper
Constructor Details
#initialize(name, options = {}) ⇒ Base
Initializes sensor and dumps it to redis
19 20 21 22 23 24 25 26 27 |
# File 'lib/pulse-meter/sensor/base.rb', line 19 def initialize(name, ={}) @name = name.to_s if [:annotation] annotate([:annotation]) end raise BadSensorName, @name unless @name =~ /\A\w+\z/ raise RedisNotInitialized unless PulseMeter.redis dump! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/pulse-meter/sensor/base.rb', line 12 def name @name end |
#redis ⇒ Object
Returns Redis instance
9 10 11 |
# File 'lib/pulse-meter/sensor/base.rb', line 9 def redis @redis end |
Instance Method Details
#annotate(description) ⇒ Object
Saves annotation to Redis
36 37 38 |
# File 'lib/pulse-meter/sensor/base.rb', line 36 def annotate(description) redis.set(desc_key, description) end |
#annotation ⇒ String
Retrieves annotation from Redis
42 43 44 |
# File 'lib/pulse-meter/sensor/base.rb', line 42 def annotation redis.get(desc_key) end |
#cleanup ⇒ Object
Cleans up all sensor metadata in Redis
47 48 49 50 |
# File 'lib/pulse-meter/sensor/base.rb', line 47 def cleanup redis.del(desc_key) cleanup_dump end |
#event(value) ⇒ Object
This method is abstract.
Processes event
54 55 56 |
# File 'lib/pulse-meter/sensor/base.rb', line 54 def event(value) # do nothing here end |