Class: Sensors::Chip
- Inherits:
-
Object
- Object
- Sensors::Chip
- Defined in:
- lib/sensors/chip.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #features ⇒ Object
-
#initialize(name = nil) ⇒ Chip
constructor
A new instance of Chip.
- #inspect ⇒ Object
- #to_ffi ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ Chip
Returns a new instance of Chip.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sensors/chip.rb', line 37 def initialize (name=nil) if name.is_a?(C::ChipName) || name.is_a?(FFI::Pointer) @chip_name = name.is_a?(C::ChipName) ? name : C::ChipName.new(name) name = nil else @chip_name = C::ChipName.new C::sensors_parse_chip_name(name, @chip_name) ObjectSpace.define_finalizer self, Chip.finalizer(@chip_name.pointer) end FFI::MemoryPointer.new(512).tap {|pointer| @name = if C::sensors_snprintf_chip_name(pointer, 512, to_ffi) < 0 name else pointer.typecast(:string) end } end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
35 36 37 |
# File 'lib/sensors/chip.rb', line 35 def name @name end |
Class Method Details
.finalizer(pointer) ⇒ Object
57 58 59 60 61 |
# File 'lib/sensors/chip.rb', line 57 def self.finalizer (pointer) proc { C::sensors_free_chip_name(pointer) } end |
Instance Method Details
#features ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/sensors/chip.rb', line 63 def features Enumerator.new do |e| number = FFI::MemoryPointer.new :int until (feature = C::sensors_get_features(to_ffi, number)).null? e << Feature.new(self, feature) end end end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/sensors/chip.rb', line 75 def inspect "#<Chip: #{name || 'unknown'}>" end |
#to_ffi ⇒ Object
79 80 81 |
# File 'lib/sensors/chip.rb', line 79 def to_ffi @chip_name end |