| 
									
										
										
										
											2013-03-17 13:30:12 -05:00
										 |  |  | require 'hardware_compat' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-02 13:17:15 -06:00
										 |  |  | class Hardware | 
					
						
							| 
									
										
										
										
											2013-03-17 13:30:12 -05:00
										 |  |  |   module CPU extend self | 
					
						
							|  |  |  |     def type | 
					
						
							|  |  |  |       @type || :dunno | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def family | 
					
						
							|  |  |  |       @family || :dunno | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def cores | 
					
						
							|  |  |  |       @cores || 1
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def bits | 
					
						
							|  |  |  |       @bits || 64
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def is_32_bit? | 
					
						
							|  |  |  |       bits == 32
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def is_64_bit? | 
					
						
							|  |  |  |       bits == 64
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-10 17:33:06 +00:00
										 |  |  |   case RUBY_PLATFORM.downcase | 
					
						
							|  |  |  |   when /darwin/ | 
					
						
							|  |  |  |     require 'os/mac/hardware' | 
					
						
							| 
									
										
										
										
											2013-03-17 13:30:12 -05:00
										 |  |  |     CPU.extend MacCPUs | 
					
						
							| 
									
										
										
										
											2013-03-10 17:33:06 +00:00
										 |  |  |   when /linux/ | 
					
						
							|  |  |  |     require 'os/linux/hardware' | 
					
						
							| 
									
										
										
										
											2013-03-17 13:30:12 -05:00
										 |  |  |     CPU.extend LinuxCPUs | 
					
						
							| 
									
										
										
										
											2013-03-10 17:33:06 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     raise "The system `#{`uname`.chomp}' is not supported." | 
					
						
							| 
									
										
										
										
											2009-09-02 13:17:15 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 09:35:19 -08:00
										 |  |  |   def self.cores_as_words | 
					
						
							|  |  |  |     case Hardware.processor_count | 
					
						
							|  |  |  |     when 1 then 'single' | 
					
						
							|  |  |  |     when 2 then 'dual' | 
					
						
							|  |  |  |     when 4 then 'quad' | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Hardware.processor_count | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-02 13:17:15 -06:00
										 |  |  | end |