sys-cpu 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d1988f097f8efd9447e33fd135d373fccc9cbfa699a2c67257361e50367a661
4
- data.tar.gz: e2abfb34d4afe062b47cac1bc1a73fb79a609dc55c5070d03bee09f7c841f9d9
3
+ metadata.gz: c9b8cf15d0019738569df3847184952320df08960cc039e52ed819ae7a649d3f
4
+ data.tar.gz: b38dc203121fa564f8c6d156e99821eb33ea1b7db7070e261262458531b7393a
5
5
  SHA512:
6
- metadata.gz: 9fd5d3cabaf78df0ea92dae46081325dcd9569cfd10af7c071cf2532d87b09ec191d15377fe1ce5aa2acf34db49d09ccfee0c6c4bdb7dec914ba4be61e57565d
7
- data.tar.gz: c11064f1318983072179f78c2fb3b2eb4ac23b8bbe0b266c0e0ba7174e3f77b4b9ccb27184b4ffdb70c07bcef771ec36ee55b8cb3a8c0a85c2c2ee3374dfd97f
6
+ metadata.gz: 7bbce2f399977b559cbbd799b0b2fb9c5343627e316d8d8c1a58fd61878452491ffd3bf4dc18851c1a8c76d383b7b9aea2e9f7b8bae03e465fd94cd602f1e802
7
+ data.tar.gz: 1ac9b193bf154c24b884ac0638a6bc2ff7ee959adaf0dac0d05eb8e47a4f4eadbc5e0f019cd50100cc5e30c0ac02ec8db6f10c89b1acf3404f30f64ea5341818
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.2 - 25-Jan-2021
2
+ * Fixed issues where things that were meant to be private weren't actually private.
3
+
1
4
  ## 1.0.1 - 20-Dec-2020
2
5
  * Switched from rdoc to markdown.
3
6
 
data/README.md CHANGED
@@ -64,7 +64,7 @@ https://github.com/djberg96/sys-cpu
64
64
  Apache-2.0
65
65
 
66
66
  ## Copyright
67
- (C) 2003-2020 Daniel J. Berger, All Rights Reserved
67
+ (C) 2003-2021 Daniel J. Berger, All Rights Reserved
68
68
 
69
69
  ## Warranty
70
70
  This package is provided "as is" and without any express or
@@ -5,7 +5,7 @@ require 'rbconfig'
5
5
  module Sys
6
6
  class CPU
7
7
  # The version of the sys-cpu gem.
8
- VERSION = '1.0.1'.freeze
8
+ VERSION = '1.0.2'.freeze
9
9
  end
10
10
  end
11
11
 
@@ -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
 
@@ -81,9 +81,9 @@ module Sys
81
81
  def self.architecture
82
82
  case CPU_ARRAY.first['cpu_family']
83
83
  when '3'
84
- "x86"
84
+ 'x86'
85
85
  when '6'
86
- "x86_64"
86
+ 'x86_64'
87
87
  else
88
88
  nil
89
89
  end
@@ -101,27 +101,25 @@ module Sys
101
101
  CPU_ARRAY.first['cpu_mhz'].to_f.round
102
102
  end
103
103
 
104
- private
105
-
106
104
  # Create singleton methods for each of the attributes.
107
105
  #
108
106
  def self.method_missing(id, arg=0)
109
107
  raise NoMethodError, "'#{id}'" unless CPU_ARRAY[arg].has_key?(id.to_s)
110
108
  rv = CPU_ARRAY[arg][id.to_s]
111
109
  if rv.nil?
112
- id = id.to_s + "?"
110
+ id = id.to_s + '?'
113
111
  rv = CPU_ARRAY[arg][id]
114
112
  end
115
113
  rv
116
114
  end
117
115
 
118
- public
116
+ private_class_method :method_missing
119
117
 
120
118
  # Returns a 3 element Array corresponding to the 1, 5 and 15 minute
121
119
  # load average for the system.
122
120
  #
123
121
  def self.load_avg
124
- load_avg_file = "/proc/loadavg"
122
+ load_avg_file = '/proc/loadavg'
125
123
  IO.readlines(load_avg_file).first.split[0..2].map{ |e| e.to_f }
126
124
  end
127
125
 
@@ -142,7 +140,7 @@ module Sys
142
140
  # Note that older kernels may not necessarily include some of these fields.
143
141
  #
144
142
  def self.cpu_stats
145
- cpu_stat_file = "/proc/stat"
143
+ cpu_stat_file = '/proc/stat'
146
144
  hash = {} # Hash needed for multi-cpu systems
147
145
 
148
146
  lines = IO.readlines(cpu_stat_file)
@@ -153,11 +151,11 @@ module Sys
153
151
 
154
152
  # Some machines list a 'cpu' and a 'cpu0'. In this case only
155
153
  # return values for the numbered cpu entry.
156
- 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/
157
155
  next
158
156
  end
159
157
 
160
- 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.
161
159
  hash[array[0]] = vals
162
160
  }
163
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
@@ -112,7 +112,7 @@ module Sys
112
112
  end
113
113
 
114
114
  if sysctlbyname(name, optr, size, nil, 0) < 0
115
- raise Error, "sysctlbyname function failed"
115
+ raise Error, 'sysctlbyname function failed'
116
116
  end
117
117
 
118
118
  optr.read_string
@@ -125,7 +125,7 @@ module Sys
125
125
  size.write_int(buf.size)
126
126
 
127
127
  if sysctl(mib, 2, buf, size, nil, 0) < 0
128
- raise Error, "sysctl function failed"
128
+ raise Error, 'sysctl function failed'
129
129
  end
130
130
 
131
131
  buf.strip
@@ -144,7 +144,7 @@ module Sys
144
144
  size.write_long(optr.size)
145
145
 
146
146
  if sysctlbyname('hw.ncpu', optr, size, nil, 0) < 0
147
- raise Error, "sysctlbyname failed"
147
+ raise Error, 'sysctlbyname failed'
148
148
  end
149
149
 
150
150
  optr.read_long
@@ -152,7 +152,7 @@ module Sys
152
152
  num = sysconf(SC_NPROCESSORS_ONLN)
153
153
 
154
154
  if num < 0
155
- raise Error, "sysconf function failed"
155
+ raise Error, 'sysconf function failed'
156
156
  end
157
157
 
158
158
  num
@@ -165,10 +165,10 @@ module Sys
165
165
  size.write_int(buf.size)
166
166
 
167
167
  if sysctl(mib, 2, buf, size, nil, 0) < 0
168
- raise Error, "sysctl function failed"
168
+ raise Error, 'sysctl function failed'
169
169
  end
170
170
 
171
- buf.strip.unpack("C").first
171
+ buf.strip.unpack('C').first
172
172
  end
173
173
  end
174
174
 
@@ -186,7 +186,7 @@ module Sys
186
186
  size.write_int(buf.size)
187
187
 
188
188
  if sysctl(mib, 2, buf, size, nil, 0) < 0
189
- raise Error, "sysctl function failed"
189
+ raise Error, 'sysctl function failed'
190
190
  end
191
191
 
192
192
  buf.strip
@@ -194,7 +194,7 @@ module Sys
194
194
  buf = 0.chr * 257
195
195
 
196
196
  if sysinfo(SI_MACHINE, buf, buf.size) < 0
197
- raise Error, "sysinfo function failed"
197
+ raise Error, 'sysinfo function failed'
198
198
  end
199
199
 
200
200
  buf.strip
@@ -210,19 +210,19 @@ module Sys
210
210
 
211
211
  size.write_long(ptr.size)
212
212
 
213
- if sysctlbyname("hw.cputype", ptr, size, nil, 0) < 0
214
- raise "sysctlbyname function failed"
213
+ if sysctlbyname('hw.cputype', ptr, size, nil, 0) < 0
214
+ raise 'sysctlbyname function failed'
215
215
  end
216
216
 
217
217
  case ptr.read_long
218
218
  when CPU_TYPE_X86, CPU_TYPE_X86_64
219
- "Intel"
219
+ 'Intel'
220
220
  when CPU_TYPE_SPARC
221
- "Sparc"
221
+ 'Sparc'
222
222
  when CPU_TYPE_POWERPC, CPU_TYPE_POWERPC64
223
- "PowerPC"
223
+ 'PowerPC'
224
224
  else
225
- "Unknown"
225
+ 'Unknown'
226
226
  end
227
227
  else
228
228
  if respond_to?(:sysctl, true)
@@ -234,7 +234,7 @@ module Sys
234
234
  size.write_int(buf.size)
235
235
 
236
236
  if sysctl(mib, 2, buf, size, nil, 0) < 0
237
- raise Error, "sysctl function failed"
237
+ raise Error, 'sysctl function failed'
238
238
  end
239
239
 
240
240
  buf.strip
@@ -244,7 +244,7 @@ module Sys
244
244
  # Some systems start at 0, some at 1
245
245
  if processor_info(0, pinfo) < 0
246
246
  if processor_info(1, pinfo) < 0
247
- raise Error, "process_info function failed"
247
+ raise Error, 'process_info function failed'
248
248
  end
249
249
  end
250
250
 
@@ -269,7 +269,7 @@ module Sys
269
269
  end
270
270
 
271
271
  if sysctlbyname(name, optr, size, nil, 0) < 0
272
- raise Error, "sysctlbyname failed"
272
+ raise Error, 'sysctlbyname failed'
273
273
  end
274
274
 
275
275
  if RbConfig::CONFIG['host_os'] =~ /darwin/i
@@ -286,17 +286,17 @@ module Sys
286
286
  size.write_int(buf.size)
287
287
 
288
288
  if sysctl(mib, 2, buf, size, nil, 0) < 0
289
- raise Error, "sysctl function failed"
289
+ raise Error, 'sysctl function failed'
290
290
  end
291
291
 
292
- buf.unpack("I*").first / 1000000
292
+ buf.unpack('I*').first / 1000000
293
293
  else
294
294
  pinfo = ProcInfo.new
295
295
 
296
296
  # Some systems start at 0, some at 1
297
297
  if processor_info(0, pinfo) < 0
298
298
  if processor_info(1, pinfo) < 0
299
- raise Error, "process_info function failed"
299
+ raise Error, 'process_info function failed'
300
300
  end
301
301
  end
302
302
 
@@ -312,7 +312,7 @@ module Sys
312
312
  loadavg = FFI::MemoryPointer.new(:double, 3)
313
313
 
314
314
  if getloadavg(loadavg, loadavg.size) < 0
315
- raise Error, "getloadavg function failed"
315
+ raise Error, 'getloadavg function failed'
316
316
  end
317
317
 
318
318
  loadavg.get_array_of_double(0, 3)
@@ -330,7 +330,7 @@ module Sys
330
330
 
331
331
  if processor_info(0, pinfo) < 0
332
332
  if processor_info(1, pinfo) < 0
333
- raise Error, "process_info function failed"
333
+ raise Error, 'process_info function failed'
334
334
  end
335
335
  end
336
336
 
@@ -348,24 +348,24 @@ module Sys
348
348
  pinfo = ProcInfo.new
349
349
 
350
350
  if processor_info(num, pinfo) < 0
351
- raise Error, "process_info function failed"
351
+ raise Error, 'process_info function failed'
352
352
  end
353
353
 
354
354
  case pinfo[:pi_state].to_i
355
355
  when P_ONLINE
356
- "online"
356
+ 'online'
357
357
  when P_OFFLINE
358
- "offline"
358
+ 'offline'
359
359
  when P_POWEROFF
360
- "poweroff"
360
+ 'poweroff'
361
361
  when P_FAULTED
362
- "faulted"
362
+ 'faulted'
363
363
  when P_NOINTR
364
- "nointr"
364
+ 'nointr'
365
365
  when P_SPARE
366
- "spare"
366
+ 'spare'
367
367
  else
368
- "unknown"
368
+ 'unknown'
369
369
  end
370
370
  end
371
371
  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
 
@@ -280,517 +280,535 @@ module Sys
280
280
  def self.get_cmec(num)
281
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