sys-cpu 0.8.3 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,20 +5,20 @@ module Sys
5
5
 
6
6
  # :stopdoc:
7
7
 
8
- private
9
-
10
- cpu_file = "/proc/cpuinfo"
8
+ cpu_file = '/proc/cpuinfo'
11
9
  cpu_hash = {}
12
10
  CPU_ARRAY = []
13
11
 
12
+ private_constant :CPU_ARRAY
13
+
14
14
  # Parse the info out of the /proc/cpuinfo file
15
15
  IO.foreach(cpu_file){ |line|
16
16
  line.strip!
17
17
  next if line.empty?
18
18
 
19
- key, val = line.split(":")
19
+ key, val = line.split(':')
20
20
  key.strip!
21
- key.gsub!(/\s+/,"_")
21
+ key.gsub!(/\s+/,'_')
22
22
  key.downcase!
23
23
  val.strip! if val
24
24
 
@@ -39,15 +39,15 @@ module Sys
39
39
 
40
40
  CPU_ARRAY.push(cpu_hash)
41
41
 
42
- public
43
-
44
42
  # :startdoc:
45
43
 
46
44
  class CPU
47
45
 
48
46
  # :stopdoc:
49
47
 
50
- CPUStruct = Struct.new("CPUStruct", *CPU_ARRAY.first.keys)
48
+ CPUStruct = Struct.new('CPUStruct', *CPU_ARRAY.first.keys)
49
+
50
+ private_constant :CPUStruct
51
51
 
52
52
  # :startdoc:
53
53
 
@@ -70,26 +70,56 @@ module Sys
70
70
  array unless block_given?
71
71
  end
72
72
 
73
- private
73
+ # Return the total number of logical CPU on the system.
74
+ #
75
+ def self.num_cpu
76
+ CPU_ARRAY.size
77
+ end
78
+
79
+ # Return the architecture of the CPU.
80
+ #
81
+ def self.architecture
82
+ case CPU_ARRAY.first['cpu_family']
83
+ when '3'
84
+ 'x86'
85
+ when '6'
86
+ 'x86_64'
87
+ else
88
+ nil
89
+ end
90
+ end
91
+
92
+ # Returns a string indicating the CPU model.
93
+ #
94
+ def self.model
95
+ CPU_ARRAY.first['model_name']
96
+ end
97
+
98
+ # Returns an integer indicating the speed of the CPU.
99
+ #
100
+ def self.freq
101
+ CPU_ARRAY.first['cpu_mhz'].to_f.round
102
+ end
74
103
 
75
104
  # Create singleton methods for each of the attributes.
76
105
  #
77
106
  def self.method_missing(id, arg=0)
107
+ raise NoMethodError, "'#{id}'" unless CPU_ARRAY[arg].has_key?(id.to_s)
78
108
  rv = CPU_ARRAY[arg][id.to_s]
79
109
  if rv.nil?
80
- id = id.to_s + "?"
110
+ id = id.to_s + '?'
81
111
  rv = CPU_ARRAY[arg][id]
82
112
  end
83
113
  rv
84
114
  end
85
115
 
86
- public
116
+ private_class_method :method_missing
87
117
 
88
118
  # Returns a 3 element Array corresponding to the 1, 5 and 15 minute
89
119
  # load average for the system.
90
120
  #
91
121
  def self.load_avg
92
- load_avg_file = "/proc/loadavg"
122
+ load_avg_file = '/proc/loadavg'
93
123
  IO.readlines(load_avg_file).first.split[0..2].map{ |e| e.to_f }
94
124
  end
95
125
 
@@ -110,7 +140,7 @@ module Sys
110
140
  # Note that older kernels may not necessarily include some of these fields.
111
141
  #
112
142
  def self.cpu_stats
113
- cpu_stat_file = "/proc/stat"
143
+ cpu_stat_file = '/proc/stat'
114
144
  hash = {} # Hash needed for multi-cpu systems
115
145
 
116
146
  lines = IO.readlines(cpu_stat_file)
@@ -121,11 +151,11 @@ module Sys
121
151
 
122
152
  # Some machines list a 'cpu' and a 'cpu0'. In this case only
123
153
  # return values for the numbered cpu entry.
124
- if lines[i].split[0] == "cpu" && lines[i+1].split[0] =~ /cpu\d/
154
+ if lines[i].split[0] == 'cpu' && lines[i+1].split[0] =~ /cpu\d/
125
155
  next
126
156
  end
127
157
 
128
- vals = array[1..-1].map{ |e| e = e.to_i / 100 } # 100 jiffies/sec.
158
+ vals = array[1..-1].map{ |e| e.to_i / 100 } # 100 jiffies/sec.
129
159
  hash[array[0]] = vals
130
160
  }
131
161
 
@@ -95,7 +95,7 @@ module Sys
95
95
  buf = 0.chr * 257
96
96
 
97
97
  if sysinfo(SI_ARCHITECTURE, buf, buf.size) < 0
98
- raise Error, "sysinfo function failed"
98
+ raise Error, 'sysinfo function failed'
99
99
  end
100
100
 
101
101
  buf.strip
@@ -105,14 +105,8 @@ module Sys
105
105
 
106
106
  size.write_int(optr.size)
107
107
 
108
- if RbConfig::CONFIG['host_os'] =~ /darwin/i
109
- name = 'hw.machine'
110
- else
111
- name = 'hw.machine_arch'
112
- end
113
-
114
- if sysctlbyname(name, optr, size, nil, 0) < 0
115
- raise Error, "sysctlbyname function failed"
108
+ if sysctlbyname('hw.machine_arch', optr, size, nil, 0) < 0
109
+ raise Error, 'sysctlbyname function failed'
116
110
  end
117
111
 
118
112
  optr.read_string
@@ -125,7 +119,7 @@ module Sys
125
119
  size.write_int(buf.size)
126
120
 
127
121
  if sysctl(mib, 2, buf, size, nil, 0) < 0
128
- raise Error, "sysctl function failed"
122
+ raise Error, 'sysctl function failed'
129
123
  end
130
124
 
131
125
  buf.strip
@@ -144,7 +138,7 @@ module Sys
144
138
  size.write_long(optr.size)
145
139
 
146
140
  if sysctlbyname('hw.ncpu', optr, size, nil, 0) < 0
147
- raise Error, "sysctlbyname failed"
141
+ raise Error, 'sysctlbyname failed'
148
142
  end
149
143
 
150
144
  optr.read_long
@@ -152,7 +146,7 @@ module Sys
152
146
  num = sysconf(SC_NPROCESSORS_ONLN)
153
147
 
154
148
  if num < 0
155
- raise Error, "sysconf function failed"
149
+ raise Error, 'sysconf function failed'
156
150
  end
157
151
 
158
152
  num
@@ -165,10 +159,10 @@ module Sys
165
159
  size.write_int(buf.size)
166
160
 
167
161
  if sysctl(mib, 2, buf, size, nil, 0) < 0
168
- raise Error, "sysctl function failed"
162
+ raise Error, 'sysctl function failed'
169
163
  end
170
164
 
171
- buf.strip.unpack("C").first
165
+ buf.strip.unpack('C').first
172
166
  end
173
167
  end
174
168
 
@@ -186,7 +180,7 @@ module Sys
186
180
  size.write_int(buf.size)
187
181
 
188
182
  if sysctl(mib, 2, buf, size, nil, 0) < 0
189
- raise Error, "sysctl function failed"
183
+ raise Error, 'sysctl function failed'
190
184
  end
191
185
 
192
186
  buf.strip
@@ -194,7 +188,7 @@ module Sys
194
188
  buf = 0.chr * 257
195
189
 
196
190
  if sysinfo(SI_MACHINE, buf, buf.size) < 0
197
- raise Error, "sysinfo function failed"
191
+ raise Error, 'sysinfo function failed'
198
192
  end
199
193
 
200
194
  buf.strip
@@ -204,52 +198,30 @@ module Sys
204
198
  # Returns a string indicating the cpu model.
205
199
  #
206
200
  def self.model
207
- if RbConfig::CONFIG['host_os'] =~ /darwin/i
208
- ptr = FFI::MemoryPointer.new(:long)
209
- size = FFI::MemoryPointer.new(:size_t)
201
+ if respond_to?(:sysctl, true)
202
+ buf = 0.chr * 64
203
+ mib = FFI::MemoryPointer.new(:int, 2)
204
+ size = FFI::MemoryPointer.new(:long, 1)
210
205
 
211
- size.write_long(ptr.size)
206
+ mib.write_array_of_int([CTL_HW, HW_MODEL])
207
+ size.write_int(buf.size)
212
208
 
213
- if sysctlbyname("hw.cputype", ptr, size, nil, 0) < 0
214
- raise "sysctlbyname function failed"
209
+ if sysctl(mib, 2, buf, size, nil, 0) < 0
210
+ raise Error, 'sysctl function failed'
215
211
  end
216
212
 
217
- case ptr.read_long
218
- when CPU_TYPE_X86, CPU_TYPE_X86_64
219
- "Intel"
220
- when CPU_TYPE_SPARC
221
- "Sparc"
222
- when CPU_TYPE_POWERPC, CPU_TYPE_POWERPC64
223
- "PowerPC"
224
- else
225
- "Unknown"
226
- end
213
+ buf.strip
227
214
  else
228
- if respond_to?(:sysctl, true)
229
- buf = 0.chr * 64
230
- mib = FFI::MemoryPointer.new(:int, 2)
231
- size = FFI::MemoryPointer.new(:long, 1)
232
-
233
- mib.write_array_of_int([CTL_HW, HW_MODEL])
234
- size.write_int(buf.size)
235
-
236
- if sysctl(mib, 2, buf, size, nil, 0) < 0
237
- raise Error, "sysctl function failed"
238
- end
239
-
240
- buf.strip
241
- else
242
- pinfo = ProcInfo.new
215
+ pinfo = ProcInfo.new
243
216
 
244
- # Some systems start at 0, some at 1
245
- if processor_info(0, pinfo) < 0
246
- if processor_info(1, pinfo) < 0
247
- raise Error, "process_info function failed"
248
- end
217
+ # Some systems start at 0, some at 1
218
+ if processor_info(0, pinfo) < 0
219
+ if processor_info(1, pinfo) < 0
220
+ raise Error, 'process_info function failed'
249
221
  end
250
-
251
- pinfo[:pi_processor_type].to_s
252
222
  end
223
+
224
+ pinfo[:pi_processor_type].to_s
253
225
  end
254
226
  end
255
227
 
@@ -269,14 +241,10 @@ module Sys
269
241
  end
270
242
 
271
243
  if sysctlbyname(name, optr, size, nil, 0) < 0
272
- raise Error, "sysctlbyname failed"
244
+ raise Error, 'sysctlbyname failed'
273
245
  end
274
246
 
275
- if RbConfig::CONFIG['host_os'] =~ /darwin/i
276
- optr.read_long / 1000000
277
- else
278
- optr.read_long
279
- end
247
+ optr.read_long
280
248
  elsif respond_to?(:sysctl, true)
281
249
  buf = 0.chr * 16
282
250
  mib = FFI::MemoryPointer.new(:int, 2)
@@ -286,17 +254,17 @@ module Sys
286
254
  size.write_int(buf.size)
287
255
 
288
256
  if sysctl(mib, 2, buf, size, nil, 0) < 0
289
- raise Error, "sysctl function failed"
257
+ raise Error, 'sysctl function failed'
290
258
  end
291
259
 
292
- buf.unpack("I*").first / 1000000
260
+ buf.unpack('I*').first / 1000000
293
261
  else
294
262
  pinfo = ProcInfo.new
295
263
 
296
264
  # Some systems start at 0, some at 1
297
265
  if processor_info(0, pinfo) < 0
298
266
  if processor_info(1, pinfo) < 0
299
- raise Error, "process_info function failed"
267
+ raise Error, 'process_info function failed'
300
268
  end
301
269
  end
302
270
 
@@ -312,7 +280,7 @@ module Sys
312
280
  loadavg = FFI::MemoryPointer.new(:double, 3)
313
281
 
314
282
  if getloadavg(loadavg, loadavg.size) < 0
315
- raise Error, "getloadavg function failed"
283
+ raise Error, 'getloadavg function failed'
316
284
  end
317
285
 
318
286
  loadavg.get_array_of_double(0, 3)
@@ -330,7 +298,7 @@ module Sys
330
298
 
331
299
  if processor_info(0, pinfo) < 0
332
300
  if processor_info(1, pinfo) < 0
333
- raise Error, "process_info function failed"
301
+ raise Error, 'process_info function failed'
334
302
  end
335
303
  end
336
304
 
@@ -348,24 +316,24 @@ module Sys
348
316
  pinfo = ProcInfo.new
349
317
 
350
318
  if processor_info(num, pinfo) < 0
351
- raise Error, "process_info function failed"
319
+ raise Error, 'process_info function failed'
352
320
  end
353
321
 
354
322
  case pinfo[:pi_state].to_i
355
323
  when P_ONLINE
356
- "online"
324
+ 'online'
357
325
  when P_OFFLINE
358
- "offline"
326
+ 'offline'
359
327
  when P_POWEROFF
360
- "poweroff"
328
+ 'poweroff'
361
329
  when P_FAULTED
362
- "faulted"
330
+ 'faulted'
363
331
  when P_NOINTR
364
- "nointr"
332
+ 'nointr'
365
333
  when P_SPARE
366
- "spare"
334
+ 'spare'
367
335
  else
368
- "unknown"
336
+ 'unknown'
369
337
  end
370
338
  end
371
339
  end
@@ -17,10 +17,10 @@ module Sys
17
17
  # Error raised if any of the Sys::CPU methods fail.
18
18
  class Error < StandardError; end
19
19
 
20
- private
21
-
22
20
  # Base connect string
23
- BASE_CS = "winmgmts:{impersonationLevel=impersonate}" # :nodoc:
21
+ BASE_CS = 'winmgmts:{impersonationLevel=impersonate}' # :nodoc:
22
+
23
+ private_constant :BASE_CS
24
24
 
25
25
  # Fields used in the CPUStruct
26
26
  fields = %w[
@@ -71,9 +71,9 @@ module Sys
71
71
  ]
72
72
 
73
73
  # The struct returned by the CPU.processors method
74
- CPUStruct = Struct.new("CPUStruct", *fields) # :nodoc:
74
+ CPUStruct = Struct.new('CPUStruct', *fields) # :nodoc:
75
75
 
76
- public
76
+ private_constant :CPUStruct
77
77
 
78
78
  # Returns the +host+ CPU's architecture, or nil if it cannot be
79
79
  # determined.
@@ -85,7 +85,7 @@ module Sys
85
85
  rescue WIN32OLERuntimeError => e
86
86
  raise Error, e
87
87
  else
88
- self.get_cpu_arch(wmi.Architecture)
88
+ get_cpu_arch(wmi.Architecture)
89
89
  end
90
90
  end
91
91
 
@@ -101,7 +101,7 @@ module Sys
101
101
  rescue WIN32OLERuntimeError => e
102
102
  raise Error, e
103
103
  else
104
- return wmi.CurrentClockSpeed
104
+ wmi.CurrentClockSpeed
105
105
  end
106
106
  end
107
107
 
@@ -120,7 +120,7 @@ module Sys
120
120
  rescue WIN32OLERuntimeError => e
121
121
  raise Error, e
122
122
  else
123
- return wmi.LoadPercentage
123
+ wmi.LoadPercentage
124
124
  end
125
125
  end
126
126
 
@@ -133,7 +133,7 @@ module Sys
133
133
  rescue WIN32OLERuntimeError => e
134
134
  raise Error, e
135
135
  else
136
- return wmi.Name
136
+ wmi.Name
137
137
  end
138
138
  end
139
139
 
@@ -148,7 +148,7 @@ module Sys
148
148
  rescue WIN32OLERuntimeError => e
149
149
  raise Error, e
150
150
  else
151
- return wmi.NumberOfProcessors
151
+ wmi.NumberOfProcessors
152
152
  end
153
153
  end
154
154
 
@@ -208,13 +208,13 @@ module Sys
208
208
  rescue WIN32OLERuntimeError => e
209
209
  raise Error, e
210
210
  else
211
- wmi.InstancesOf("Win32_Processor").each{ |cpu|
211
+ wmi.InstancesOf('Win32_Processor').each{ |cpu|
212
212
  yield CPUStruct.new(
213
213
  cpu.AddressWidth,
214
- self.get_cpu_arch(cpu.Architecture),
215
- self.get_availability(cpu.Availability),
214
+ get_cpu_arch(cpu.Architecture),
215
+ get_availability(cpu.Availability),
216
216
  cpu.Caption,
217
- self.get_cmec(cpu.ConfigManagerErrorCode),
217
+ get_cmec(cpu.ConfigManagerErrorCode),
218
218
  cpu.ConfigManagerUserConfig,
219
219
  get_status(cpu.CpuStatus),
220
220
  cpu.CreationClassName,
@@ -226,7 +226,7 @@ module Sys
226
226
  cpu.ErrorCleared,
227
227
  cpu.ErrorDescription,
228
228
  cpu.ExtClock,
229
- self.get_family(cpu.Family),
229
+ get_family(cpu.Family),
230
230
  cpu.InstallDate,
231
231
  cpu.L2CacheSize,
232
232
  cpu.L2CacheSpeed,
@@ -268,7 +268,7 @@ module Sys
268
268
  rescue WIN32OLERuntimeError => e
269
269
  raise Error, e
270
270
  else
271
- return wmi.Manufacturer
271
+ wmi.Manufacturer
272
272
  end
273
273
  end
274
274
 
@@ -278,519 +278,537 @@ module Sys
278
278
  # Note that this value returns nil on my system.
279
279
  #
280
280
  def self.get_cmec(num)
281
- case
281
+ case num
282
282
  when 0
283
- str = "The device is working properly."
284
- return str
283
+ str = 'The device is working properly.'
284
+ str
285
285
  when 1
286
- str = "The device is not configured correctly."
287
- return str
286
+ str = 'The device is not configured correctly.'
287
+ str
288
288
  when 2
289
- str = "Windows cannot load the driver for the device."
290
- return str
289
+ str = 'Windows cannot load the driver for the device.'
290
+ str
291
291
  when 3
292
- str = "The driver for the device might be corrupted, or the"
293
- str << " system may be running low on memory or other"
294
- str << " resources."
295
- return str
292
+ str = 'The driver for the device might be corrupted, or the'
293
+ str << ' system may be running low on memory or other'
294
+ str << ' resources.'
295
+ str
296
296
  when 4
297
- str = "The device is not working properly. One of the drivers"
298
- str << " or the registry might be corrupted."
299
- return str
297
+ str = 'The device is not working properly. One of the drivers'
298
+ str << ' or the registry might be corrupted.'
299
+ str
300
300
  when 5
301
- str = "The driver for this device needs a resource that"
302
- str << " Windows cannot manage."
303
- return str
301
+ str = 'The driver for this device needs a resource that'
302
+ str << ' Windows cannot manage.'
303
+ str
304
304
  when 6
305
- str = "The boot configuration for this device conflicts with"
306
- str << " other devices."
307
- return str
305
+ str = 'The boot configuration for this device conflicts with'
306
+ str << ' other devices.'
307
+ str
308
308
  when 7
309
- str = "Cannot filter."
310
- return str
309
+ str = 'Cannot filter.'
310
+ str
311
311
  when 8
312
- str = "The driver loader for the device is missing."
313
- return str
312
+ str = 'The driver loader for the device is missing.'
313
+ str
314
314
  when 9
315
- str = "This device is not working properly because the"
316
- str << " controlling firmware is reporting the resources"
317
- str << " for the device incorrectly."
318
- return str
315
+ str = 'This device is not working properly because the'
316
+ str << ' controlling firmware is reporting the resources'
317
+ str << ' for the device incorrectly.'
318
+ str
319
319
  when 10
320
- str = "This device cannot start."
321
- return str
320
+ str = 'This device cannot start.'
321
+ str
322
322
  when 11
323
- str = "This device failed."
324
- return str
323
+ str = 'This device failed.'
324
+ str
325
325
  when 12
326
- str = "This device cannot find enough free resources that"
327
- str << " it can use."
328
- return str
326
+ str = 'This device cannot find enough free resources that'
327
+ str << ' it can use.'
328
+ str
329
329
  when 13
330
330
  str = "Windows cannot verify this device's resources."
331
- return str
331
+ str
332
332
  when 14
333
- str = "This device cannot work properly until you restart"
334
- str << " your computer."
335
- return str
333
+ str = 'This device cannot work properly until you restart'
334
+ str << ' your computer.'
335
+ str
336
336
  when 15
337
- str = "This device is not working properly because there is"
338
- str << " probably a re-enumeration problem."
339
- return str
337
+ str = 'This device is not working properly because there is'
338
+ str << ' probably a re-enumeration problem.'
339
+ str
340
340
  when 16
341
- str = "Windows cannot identify all the resources this device "
342
- str << " uses."
343
- return str
341
+ str = 'Windows cannot identify all the resources this device '
342
+ str << ' uses.'
343
+ str
344
344
  when 17
345
- str = "This device is asking for an unknown resource type."
346
- return str
345
+ str = 'This device is asking for an unknown resource type.'
346
+ str
347
347
  when 18
348
- str = "Reinstall the drivers for this device."
349
- return str
348
+ str = 'Reinstall the drivers for this device.'
349
+ str
350
350
  when 19
351
- str = "Failure using the VXD loader."
352
- return str
351
+ str = 'Failure using the VXD loader.'
352
+ str
353
353
  when 20
354
- str = "Your registry might be corrupted."
355
- return str
354
+ str = 'Your registry might be corrupted.'
355
+ str
356
356
  when 21
357
- str = "System failure: try changing the driver for this device."
358
- str << " If that does not work, see your hardware documentation."
359
- str << " Windows is removing this device."
360
- return str
357
+ str = 'System failure: try changing the driver for this device.'
358
+ str << ' If that does not work, see your hardware documentation.'
359
+ str << ' Windows is removing this device.'
360
+ str
361
361
  when 22
362
- str = "This device is disabled."
363
- return str
362
+ str = 'This device is disabled.'
363
+ str
364
364
  when 23
365
- str = "System failure: try changing the driver for this device."
365
+ str = 'System failure: try changing the driver for this device.'
366
366
  str << "If that doesn't work, see your hardware documentation."
367
- return str
367
+ str
368
368
  when 24
369
- str = "This device is not present, not working properly, or"
370
- str << " does not have all its drivers installed."
371
- return str
369
+ str = 'This device is not present, not working properly, or'
370
+ str << ' does not have all its drivers installed.'
371
+ str
372
372
  when 25
373
- str = "Windows is still setting up this device."
374
- return str
373
+ str = 'Windows is still setting up this device.'
374
+ str
375
375
  when 26
376
- str = "Windows is still setting up this device."
377
- return str
376
+ str = 'Windows is still setting up this device.'
377
+ str
378
378
  when 27
379
- str = "This device does not have valid log configuration."
380
- return str
379
+ str = 'This device does not have valid log configuration.'
380
+ str
381
381
  when 28
382
- str = "The drivers for this device are not installed."
383
- return str
382
+ str = 'The drivers for this device are not installed.'
383
+ str
384
384
  when 29
385
- str = "This device is disabled because the firmware of the"
386
- str << " device did not give it the required resources."
387
- return str
385
+ str = 'This device is disabled because the firmware of the'
386
+ str << ' device did not give it the required resources.'
387
+ str
388
388
  when 30
389
- str = "This device is using an Interrupt Request (IRQ)"
390
- str << " resource that another device is using."
391
- return str
389
+ str = 'This device is using an Interrupt Request (IRQ)'
390
+ str << ' resource that another device is using.'
391
+ str
392
392
  when 31
393
- str = "This device is not working properly because Windows"
394
- str << " cannot load the drivers required for this device"
395
- return str
393
+ str = 'This device is not working properly because Windows'
394
+ str << ' cannot load the drivers required for this device'
395
+ str
396
396
  else
397
- return nil
397
+ nil
398
398
  end
399
399
  end
400
400
 
401
+ private_class_method :get_cmec
402
+
401
403
  # Convert an cpu architecture number to a string
402
404
  def self.get_cpu_arch(num)
403
405
  case num
404
406
  when 0
405
- return "x86"
407
+ 'x86'
406
408
  when 1
407
- return "MIPS"
409
+ 'MIPS'
408
410
  when 2
409
- return "Alpha"
411
+ 'Alpha'
410
412
  when 3
411
- return "PowerPC"
413
+ 'PowerPC'
412
414
  when 6
413
- return "IA64"
415
+ 'IA64'
414
416
  when 9
415
- return "x64"
417
+ 'x64'
416
418
  else
417
- return nil
419
+ nil
418
420
  end
419
421
  end
420
422
 
423
+ private_class_method :get_cpu_arch
424
+
421
425
  # convert an Availability number into a string
422
426
  def self.get_availability(num)
423
427
  case num
424
428
  when 1
425
- return "Other"
429
+ 'Other'
426
430
  when 2
427
- return "Unknown"
431
+ 'Unknown'
428
432
  when 3
429
- return "Running"
433
+ 'Running'
430
434
  when 4
431
- return "Warning"
435
+ 'Warning'
432
436
  when 5
433
- return "In Test"
437
+ 'In Test'
434
438
  when 6
435
- return "Not Applicable"
439
+ 'Not Applicable'
436
440
  when 7
437
- return "Power Off"
441
+ 'Power Off'
438
442
  when 8
439
- return "Off Line"
443
+ 'Off Line'
440
444
  when 9
441
- return "Off Duty"
445
+ 'Off Duty'
442
446
  when 10
443
- return "Degraded"
447
+ 'Degraded'
444
448
  when 11
445
- return "Not Installed"
449
+ 'Not Installed'
446
450
  when 12
447
- return "Install Error"
451
+ 'Install Error'
448
452
  when 13
449
- return "Power Save - Unknown"
453
+ 'Power Save - Unknown'
450
454
  when 14
451
- return "Power Save - Low Power Mode"
455
+ 'Power Save - Low Power Mode'
452
456
  when 15
453
- return "Power Save - Standby"
457
+ 'Power Save - Standby'
454
458
  when 16
455
- return "Power Cycle"
459
+ 'Power Cycle'
456
460
  when 17
457
- return "Power Save - Warning"
461
+ 'Power Save - Warning'
458
462
  when 18
459
- return "Paused"
463
+ 'Paused'
460
464
  when 19
461
- return "Not Ready"
465
+ 'Not Ready'
462
466
  when 20
463
- return "Not Configured"
467
+ 'Not Configured'
464
468
  when 21
465
- return "Quiesced"
469
+ 'Quiesced'
466
470
  else
467
- return nil
471
+ nil
468
472
  end
469
473
  end
470
474
 
475
+ private_class_method :get_availability
476
+
471
477
  # convert CpuStatus to a string form. Note that values 5 and 6 are
472
478
  # skipped because they're reserved.
473
479
  def self.get_status(num)
474
480
  case num
475
481
  when 0
476
- return "Unknown"
482
+ 'Unknown'
477
483
  when 1
478
- return "Enabled"
484
+ 'Enabled'
479
485
  when 2
480
- return "Disabled by User via BIOS Setup"
486
+ 'Disabled by User via BIOS Setup'
481
487
  when 3
482
- return "Disabled By BIOS (POST Error)"
488
+ 'Disabled By BIOS (POST Error)'
483
489
  when 4
484
- return "Idle"
490
+ 'Idle'
485
491
  when 7
486
- return "Other"
492
+ 'Other'
487
493
  else
488
- return nil
494
+ nil
489
495
  end
490
496
  end
491
497
 
498
+ private_class_method :get_status
499
+
492
500
  # Convert a family number into the equivalent string
493
501
  def self.get_family(num)
494
502
  case num
495
503
  when 1
496
- return "Other"
504
+ 'Other'
497
505
  when 2
498
- return "Unknown"
506
+ 'Unknown'
499
507
  when 3
500
- return "8086"
508
+ '8086'
501
509
  when 4
502
- return "80286"
510
+ '80286'
503
511
  when 5
504
- return "80386"
512
+ '80386'
505
513
  when 6
506
- return "80486"
514
+ '80486'
507
515
  when 7
508
- return "8087"
516
+ '8087'
509
517
  when 8
510
- return "80287"
518
+ '80287'
511
519
  when 9
512
- return "80387"
520
+ '80387'
513
521
  when 10
514
- return "80487"
522
+ '80487'
515
523
  when 11
516
- return "Pentium?"
524
+ 'Pentium?'
517
525
  when 12
518
- return "Pentium?"
526
+ 'Pentium?'
519
527
  when 13
520
- return "Pentium?"
528
+ 'Pentium?'
521
529
  when 14
522
- return "Pentium?"
530
+ 'Pentium?'
523
531
  when 15
524
- return "Celeron?"
532
+ 'Celeron?'
525
533
  when 16
526
- return "Pentium?"
534
+ 'Pentium?'
527
535
  when 17
528
- return "Pentium?"
536
+ 'Pentium?'
529
537
  when 18
530
- return "M1"
538
+ 'M1'
531
539
  when 19
532
- return "M2"
540
+ 'M2'
533
541
  when 24
534
- return "K5"
542
+ 'K5'
535
543
  when 25
536
- return "K6"
544
+ 'K6'
537
545
  when 26
538
- return "K6-2"
546
+ 'K6-2'
539
547
  when 27
540
- return "K6-3"
548
+ 'K6-3'
541
549
  when 28
542
- return "AMD"
550
+ 'AMD'
543
551
  when 29
544
- return "AMD?"
552
+ 'AMD?'
545
553
  when 30
546
- return "AMD2900"
554
+ 'AMD2900'
547
555
  when 31
548
- return "K6-2+"
556
+ 'K6-2+'
549
557
  when 32
550
- return "Power"
558
+ 'Power'
551
559
  when 33
552
- return "Power"
560
+ 'Power'
553
561
  when 34
554
- return "Power"
562
+ 'Power'
555
563
  when 35
556
- return "Power"
564
+ 'Power'
557
565
  when 36
558
- return "Power"
566
+ 'Power'
559
567
  when 37
560
- return "Power"
568
+ 'Power'
561
569
  when 38
562
- return "Power"
570
+ 'Power'
563
571
  when 39
564
- return "Power"
572
+ 'Power'
565
573
  when 48
566
- return "Alpha"
574
+ 'Alpha'
567
575
  when 49
568
- return "Alpha"
576
+ 'Alpha'
569
577
  when 50
570
- return "Alpha"
578
+ 'Alpha'
571
579
  when 51
572
- return "Alpha"
580
+ 'Alpha'
573
581
  when 52
574
- return "Alpha"
582
+ 'Alpha'
575
583
  when 53
576
- return "Alpha"
584
+ 'Alpha'
577
585
  when 54
578
- return "Alpha"
586
+ 'Alpha'
579
587
  when 55
580
- return "Alpha"
588
+ 'Alpha'
581
589
  when 64
582
- return "MIPS"
590
+ 'MIPS'
583
591
  when 65
584
- return "MIPS"
592
+ 'MIPS'
585
593
  when 66
586
- return "MIPS"
594
+ 'MIPS'
587
595
  when 67
588
- return "MIPS"
596
+ 'MIPS'
589
597
  when 68
590
- return "MIPS"
598
+ 'MIPS'
591
599
  when 69
592
- return "MIPS"
600
+ 'MIPS'
593
601
  when 80
594
- return "SPARC"
602
+ 'SPARC'
595
603
  when 81
596
- return "SuperSPARC"
604
+ 'SuperSPARC'
597
605
  when 82
598
- return "microSPARC"
606
+ 'microSPARC'
599
607
  when 83
600
- return "microSPARC"
608
+ 'microSPARC'
601
609
  when 84
602
- return "UltraSPARC"
610
+ 'UltraSPARC'
603
611
  when 85
604
- return "UltraSPARC"
612
+ 'UltraSPARC'
605
613
  when 86
606
- return "UltraSPARC"
614
+ 'UltraSPARC'
607
615
  when 87
608
- return "UltraSPARC"
616
+ 'UltraSPARC'
609
617
  when 88
610
- return "UltraSPARC"
618
+ 'UltraSPARC'
611
619
  when 96
612
- return "68040"
620
+ '68040'
613
621
  when 97
614
- return "68xxx"
622
+ '68xxx'
615
623
  when 98
616
- return "68000"
624
+ '68000'
617
625
  when 99
618
- return "68010"
626
+ '68010'
619
627
  when 100
620
- return "68020"
628
+ '68020'
621
629
  when 101
622
- return "68030"
630
+ '68030'
623
631
  when 112
624
- return "Hobbit"
632
+ 'Hobbit'
625
633
  when 120
626
- return "Crusoe?"
634
+ 'Crusoe?'
627
635
  when 121
628
- return "Crusoe?"
636
+ 'Crusoe?'
629
637
  when 128
630
- return "Weitek"
638
+ 'Weitek'
631
639
  when 130
632
- return "Itanium?"
640
+ 'Itanium?'
633
641
  when 144
634
- return "PA-RISC"
642
+ 'PA-RISC'
635
643
  when 145
636
- return "PA-RISC"
644
+ 'PA-RISC'
637
645
  when 146
638
- return "PA-RISC"
646
+ 'PA-RISC'
639
647
  when 147
640
- return "PA-RISC"
648
+ 'PA-RISC'
641
649
  when 148
642
- return "PA-RISC"
650
+ 'PA-RISC'
643
651
  when 149
644
- return "PA-RISC"
652
+ 'PA-RISC'
645
653
  when 150
646
- return "PA-RISC"
654
+ 'PA-RISC'
647
655
  when 160
648
- return "V30"
656
+ 'V30'
649
657
  when 176
650
- return "Pentium?"
658
+ 'Pentium?'
651
659
  when 177
652
- return "Pentium?"
660
+ 'Pentium?'
653
661
  when 178
654
- return "Pentium?"
662
+ 'Pentium?'
655
663
  when 179
656
- return "Intel?"
664
+ 'Intel?'
657
665
  when 180
658
- return "AS400"
666
+ 'AS400'
659
667
  when 181
660
- return "Intel?"
668
+ 'Intel?'
661
669
  when 182
662
- return "AMD"
670
+ 'AMD'
663
671
  when 183
664
- return "AMD"
672
+ 'AMD'
665
673
  when 184
666
- return "Intel?"
674
+ 'Intel?'
667
675
  when 185
668
- return "AMD"
676
+ 'AMD'
669
677
  when 190
670
- return "K7"
678
+ 'K7'
671
679
  when 200
672
- return "IBM390"
680
+ 'IBM390'
673
681
  when 201
674
- return "G4"
682
+ 'G4'
675
683
  when 202
676
- return "G5"
684
+ 'G5'
677
685
  when 250
678
- return "i860"
686
+ 'i860'
679
687
  when 251
680
- return "i960"
688
+ 'i960'
681
689
  when 260
682
- return "SH-3"
690
+ 'SH-3'
683
691
  when 261
684
- return "SH-4"
692
+ 'SH-4'
685
693
  when 280
686
- return "ARM"
694
+ 'ARM'
687
695
  when 281
688
- return "StrongARM"
696
+ 'StrongARM'
689
697
  when 300
690
- return "6x86"
698
+ '6x86'
691
699
  when 301
692
- return "MediaGX"
700
+ 'MediaGX'
693
701
  when 302
694
- return "MII"
702
+ 'MII'
695
703
  when 320
696
- return "WinChip"
704
+ 'WinChip'
697
705
  when 350
698
- return "DSP"
706
+ 'DSP'
699
707
  when 500
700
- return "Video"
708
+ 'Video'
701
709
  else
702
- return nil
710
+ nil
703
711
  end
704
712
  end
705
713
 
714
+ private_class_method :get_family
715
+
706
716
  # Convert power management capabilities number to its equivalent string
707
717
  def self.get_pmc(num)
708
718
  case num
709
719
  when 0
710
- return "Unknown"
720
+ 'Unknown'
711
721
  when 1
712
- return "Not Supported"
722
+ 'Not Supported'
713
723
  when 2
714
- return "Disabled"
724
+ 'Disabled'
715
725
  when 3
716
- return "Enabled"
726
+ 'Enabled'
717
727
  when 4
718
- return "Power Saving Modes Entered Automatically"
728
+ 'Power Saving Modes Entered Automatically'
719
729
  when 5
720
- return "Power State Settable"
730
+ 'Power State Settable'
721
731
  when 6
722
- return "Power Cycling Supported"
732
+ 'Power Cycling Supported'
723
733
  when 7
724
- return "Timed Power On Supported"
734
+ 'Timed Power On Supported'
725
735
  else
726
- return nil
736
+ nil
727
737
  end
728
738
  end
729
739
 
740
+ private_class_method :get_pmc
741
+
730
742
  # Convert a processor type into its equivalent string
731
743
  def self.get_processor_type(num)
732
744
  case num
733
745
  when 1
734
- return "Other"
746
+ 'Other'
735
747
  when 2
736
- return "Unknown"
748
+ 'Unknown'
737
749
  when 3
738
- return "Central Processor"
750
+ 'Central Processor'
739
751
  when 4
740
- return "Math Processor"
752
+ 'Math Processor'
741
753
  when 5
742
- return "DSP Processor"
754
+ 'DSP Processor'
743
755
  when 6
744
- return "Video Processor"
756
+ 'Video Processor'
745
757
  else
746
- return nil
758
+ nil
747
759
  end
748
760
  end
749
761
 
762
+ private_class_method :get_processor_type
763
+
750
764
  # Convert an upgrade method into its equivalent string
751
765
  def self.get_upgrade_method(num)
752
766
  case num
753
767
  when 1
754
- return "Other"
768
+ 'Other'
755
769
  when 2
756
- return "Unknown"
770
+ 'Unknown'
757
771
  when 3
758
- return "Daughter Board"
772
+ 'Daughter Board'
759
773
  when 4
760
- return "ZIF Socket"
774
+ 'ZIF Socket'
761
775
  when 5
762
- return "Replacement/Piggy Back"
776
+ 'Replacement/Piggy Back'
763
777
  when 6
764
- return "None"
778
+ 'None'
765
779
  when 7
766
- return "LIF Socket"
780
+ 'LIF Socket'
767
781
  when 8
768
- return "Slot 1"
782
+ 'Slot 1'
769
783
  when 9
770
- return "Slot 2"
784
+ 'Slot 2'
771
785
  when 10
772
- return "370 Pin Socket"
786
+ '370 Pin Socket'
773
787
  when 11
774
- return "Slot A"
788
+ 'Slot A'
775
789
  when 12
776
- return "Slot M"
790
+ 'Slot M'
777
791
  else
778
- return nil
792
+ nil
779
793
  end
780
794
  end
781
795
 
796
+ private_class_method :get_upgrade_method
797
+
782
798
  # Convert return values to voltage cap values (floats)
783
799
  def self.get_voltage_caps(num)
784
800
  case num
785
801
  when 1
786
- return 5.0
802
+ 5.0
787
803
  when 2
788
- return 3.3
804
+ 3.3
789
805
  when 4
790
- return 2.9
806
+ 2.9
791
807
  else
792
- return nil
808
+ nil
793
809
  end
794
810
  end
811
+
812
+ private_class_method :get_voltage_caps
795
813
  end
796
814
  end