Class: LmSensors::Feature::GenFeature

Inherits:
Object
  • Object
show all
Defined in:
lib/lmsensors/features/abs_feature.rb

Overview

The generic GenFeature class is appended to the LmSensors to handle generic formatting on feature types that generally will not need additional post-processing.

Direct Known Subclasses

Alarm, Beep, Current, Fan, Humidity, Power, Temp, Voltage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data) ⇒ GenFeature

Constructor



53
54
55
56
57
58
59
60
# File 'lib/lmsensors/features/abs_feature.rb', line 53

def initialize(name, data)
  # Attach the default formatter
  def_fmt
  # Attach the base data for this instance
  @name, @type, @subfs = name, data[:type], data
  @subfs.delete(:type) # Remove :type from the hash (for cleaner iteration)
  @unit = LmSensors::UNITS[@type] # Units
end

Instance Attribute Details

#default_formatterObject (readonly)

GenFeature :default_formatter is BASE_FMT, which returns a simple representation of the sensor subfeatures, if no clear formatting can be determined.



33
34
35
# File 'lib/lmsensors/features/abs_feature.rb', line 33

def default_formatter
  @default_formatter
end

#nameObject (readonly)

GenFeature :name is the name of the feature, such as ‘:temp1’



36
37
38
# File 'lib/lmsensors/features/abs_feature.rb', line 36

def name
  @name
end

#subfsObject (readonly)

GenFeature :subfs is a list/array of the subfeatures for this feature



39
40
41
# File 'lib/lmsensors/features/abs_feature.rb', line 39

def subfs
  @subfs
end

#typeObject (readonly)

GenFeature :type is the type of the feature, such as SF_TEMP or SF_FAN



42
43
44
# File 'lib/lmsensors/features/abs_feature.rb', line 42

def type
  @type
end

#unitObject (readonly)

GenFeature :unit is the default unit that is likely desired to represent subfeatures in this feature.

Example: :temp1 may have :temp1_input and :temp1_crit, but both
  would be formatted with 


49
50
51
# File 'lib/lmsensors/features/abs_feature.rb', line 49

def unit
  @unit
end

Instance Method Details

#def_fmtObject

Set the default formatter for the subclass. If not overridden, will be be the default for the abstract general class.



70
# File 'lib/lmsensors/features/abs_feature.rb', line 70

def def_fmt() @default_formatter = LmSensors::Feature::BASE_FMT end

#featureObject

Return just the feature keys



64
# File 'lib/lmsensors/features/abs_feature.rb', line 64

def feature() { name: @name, type: @type, unit: @unit } end

#fmt(callback = @default_formatter) ⇒ Object

Format the output struct. This uses a default formatter, but any desired formatting function can be passed. The formatter should be a lambda or proc type.



77
78
79
80
81
82
# File 'lib/lmsensors/features/abs_feature.rb', line 77

def fmt(callback=@default_formatter)
  #puts "Abstract formatter for #{self.class}"
  # If the callback is the wrong type, sue the default
  cb = Proc === callback ? callback : @default_formatter
  cb.call(self)
end