Class: LmSensors::AbsSensor
- Inherits:
-
SensorsBase
- Object
- Data
- SensorsBase
- LmSensors::AbsSensor
- Defined in:
- lib/lmsensors/sensors/abssensor.rb
Overview
AbsSensor is an abstract representation of a sensor-type object and provides a base interface for required functions (operates like a trait).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chip_name ⇒ Object
readonly
AbsSensor :chip_name is the name sensors returns for the chip.
-
#filters ⇒ Object
readonly
AbsSensor :filters are the selected feature types to return for your use case.
-
#fmap ⇒ Object
readonly
AbsSensor :fmap is a custom formatter map or the default DEF_FMAP.
-
#fmt ⇒ Object
readonly
AbsSensor :fmt is a boolean of whether or not to return the data formatted.
-
#subs ⇒ Object
readonly
AbsSensor :subs is whether to return the subfeatures or just the feature and its type.
Instance Method Summary collapse
-
#count ⇒ Object
(also: #count_s)
Get the number of sensors available for the current name (or the total number of sensors available).
-
#enum(*args) ⇒ Object
Abstract enum must be implemented by subclasses.
-
#initialize ⇒ AbsSensor
constructor
Constructor.
-
#name ⇒ Object
Get the chip_name.
-
#reset_fmap ⇒ Object
Reset the formatting map.
-
#set_filters(arr) ⇒ Object
Set the sensor’s filters, the types that will be returned on ‘.features’.
-
#set_fmap(map) ⇒ Object
Set the format mapper for the different types.
-
#toggle_fmt ⇒ Object
Toggle if the sensor will report with formatted output or unformatted.
-
#toggle_subs ⇒ Object
Toggle whether this sensor also returns subfeatures on a feature list request.
-
#unset_filters ⇒ Object
Unset the filters for this sensor.
Constructor Details
#initialize ⇒ AbsSensor
Constructor
35 36 37 38 39 40 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 35 def initialize pro_initialize unset_filters @fmt = @subs = false @fmap = LmSensors::DEF_FMAP end |
Instance Attribute Details
#chip_name ⇒ Object (readonly)
AbsSensor :chip_name is the name sensors returns for the chip
18 19 20 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 18 def chip_name @chip_name end |
#filters ⇒ Object (readonly)
AbsSensor :filters are the selected feature types to return for your use case
21 22 23 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 21 def filters @filters end |
#fmap ⇒ Object (readonly)
AbsSensor :fmap is a custom formatter map or the default DEF_FMAP
24 25 26 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 24 def fmap @fmap end |
#fmt ⇒ Object (readonly)
AbsSensor :fmt is a boolean of whether or not to return the data formatted
27 28 29 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 27 def fmt @fmt end |
#subs ⇒ Object (readonly)
AbsSensor :subs is whether to return the subfeatures or just the feature and its type
31 32 33 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 31 def subs @subs end |
Instance Method Details
#count ⇒ Object Also known as: count_s
Get the number of sensors available for the current name (or the total number of sensors available).
117 118 119 120 121 122 123 124 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 117 def count data = enum if ([Hash, Array].include?(data.class)) then # If the data is good data.count else return nil end end |
#enum(*args) ⇒ Object
Abstract enum must be implemented by subclasses
108 109 110 111 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 108 def enum(*args) STDERR.puts "::AbsSensor ERROR:: Abstract 'enum' not implemented for #{self.class}" [] end |
#name ⇒ Object
Get the chip_name
44 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 44 def name() @chip_name end |
#reset_fmap ⇒ Object
Reset the formatting map
103 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 103 def reset_fmap() @fmap = LmSensors::DEF_FMAP end |
#set_filters(arr) ⇒ Object
Set the sensor’s filters, the types that will be returned on ‘.features’.
49 50 51 52 53 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 49 def set_filters(arr) if Array === arr then @filters = arr.select { |item| LmSensors::UNITS.include? item } .sort else STDERR.puts "::Sensors ERROR:: Filters must be an array" end end |
#set_fmap(map) ⇒ Object
Set the format mapper for the different types. This method should receive a proc that maps to different feature formatters.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 74 def set_fmap(map) # Only accept a proc/lambda for format mapping if Proc === map then if map.arity != 2 then if !$LmSensorsIgnArity then STDERR.puts " ::SensorSpawner WARNING:: @fmap arity should be 2 and will\n NOT WORK without being overridden in a custom subclass.\n \n If you are receiving this message, and you have already\n overridden the subclasses and format handling, you should\n set the global variable $LmSensorsIgnArity to 'true'.\n \n This is only a warning and will not stop the map from\n being set, even if it is invalid.\n \n This warning will NOT be displayed again in this run.\n EMSG\n $LmSensorsIgnArity = true\n end\n @fmap = map\n end\n else # If it's not a proc, spit out an error\n STDERR.puts \"::Sensors ERROR:: Format map must be a proc/lambda\"\n end\nend\n" |
#toggle_fmt ⇒ Object
Toggle if the sensor will report with formatted output or unformatted. Default is to report unformatted.
68 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 68 def toggle_fmt() @fmt = !@fmt end |
#toggle_subs ⇒ Object
Toggle whether this sensor also returns subfeatures on a feature list request.
62 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 62 def toggle_subs() @subs = !@subs end |
#unset_filters ⇒ Object
Unset the filters for this sensor
57 |
# File 'lib/lmsensors/sensors/abssensor.rb', line 57 def unset_filters() @filters = [] end |