Class: DeepTest::CpuInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/cpu_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform = RUBY_PLATFORM) ⇒ CpuInfo

Returns a new instance of CpuInfo.



5
6
7
# File 'lib/deep_test/cpu_info.rb', line 5

def initialize(platform = RUBY_PLATFORM)
  @platform = platform
end

Instance Attribute Details

#platformObject

Returns the value of attribute platform.



3
4
5
# File 'lib/deep_test/cpu_info.rb', line 3

def platform
  @platform
end

Instance Method Details

#countObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deep_test/cpu_info.rb', line 9

def count
  case platform
  when /darwin/
    output = `sysctl -n hw.ncpu`
    output.strip.to_i
  when /linux/
    File.readlines("/proc/cpuinfo").inject(0) do |count, line|
      next count + 1 if line =~ /processor\s*:\s*\d+/
      count
    end
  end
end