Class: SAAL::Sensors
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(conffile = SAAL::SENSORSCONF, dbconffile = SAAL::DBCONF) ⇒ Sensors
constructor
A new instance of Sensors.
-
#method_missing(name, *args) ⇒ Object
Implements the get methods to fetch a specific sensor.
Constructor Details
#initialize(conffile = SAAL::SENSORSCONF, dbconffile = SAAL::DBCONF) ⇒ Sensors
Returns a new instance of Sensors.
8 9 10 11 12 13 14 15 |
# File 'lib/sensors.rb', line 8 def initialize(conffile=SAAL::SENSORSCONF, dbconffile=SAAL::DBCONF) @defs = YAML::load(File.new(conffile)) @dbstore = DBStore.new(dbconffile) @sensors = {} @defs.each do |name, defs| self.class.sensors_from_defs(@dbstore, name, defs).each{|s| @sensors[s.name] = s} end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Implements the get methods to fetch a specific sensor
18 19 20 21 22 23 24 25 |
# File 'lib/sensors.rb', line 18 def method_missing(name, *args) name = name.to_s if args.size == 0 && @sensors.include?(name) @sensors[name] else raise NoMethodError, "undefined method \"#{name}\" for #{self}" end end |
Class Method Details
.sensors_from_defs(dbstore, name, defs, opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sensors.rb', line 31 def self.sensors_from_defs(dbstore, name, defs, opts={}) if defs['onewire'] return [Sensor.new(dbstore, name, OWSensor.new(defs['onewire'], opts), defs, opts)] elsif defs['dinrelay'] og = DINRelay::OutletGroup.new(defs['dinrelay']) outlet_names = defs['dinrelay']['outlets'] || [] outlet_descriptions = defs['dinrelay']['descriptions'] || [] return outlet_names.map do |num, oname| defs.merge!('name' => outlet_descriptions[num]) Sensor.new(dbstore, oname, DINRelay::Outlet.new(num.to_i, og), defs, opts) end else raise UnknownSensorType, "Couldn't figure out a valid sensor type " "from the configuration for #{name}" end end |
Instance Method Details
#each ⇒ Object
27 28 29 |
# File 'lib/sensors.rb', line 27 def each @sensors.each{|name, sensor| yield sensor} end |