Class: Sensors::Chip

Inherits:
Object
  • Object
show all
Defined in:
lib/sensors/chip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#featuresObject



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

#inspectObject



75
76
77
# File 'lib/sensors/chip.rb', line 75

def inspect
  "#<Chip: #{name || 'unknown'}>"
end

#to_ffiObject



79
80
81
# File 'lib/sensors/chip.rb', line 79

def to_ffi
  @chip_name
end