Module: OSName
- Defined in:
- lib/os_name.rb,
lib/os_name/version.rb
Overview
Operating System Name
Constant Summary collapse
- WIN32 =
Win32 platform version mapping
{ '6.4' => '10', '6.3' => '8.1', '6.2' => '8', '6.1' => '7', '6.0' => 'Vista', '5.1' => 'XP', '5.0' => '2000', '4.9' => 'ME', '4.1' => '98', '4.0' => '95' }
- OSX =
OS X platform version mapping
{ '14' => 'Yosemite', '13' => 'Mavericks', '12' => 'Mountain Lion', '11' => 'Lion', '10' => 'Snow Leopard', '9' => 'Leopard', '8' => 'Tiger', '7' => 'Panther', '6' => 'Jaguar', '5' => 'Puma' }
- VERSION =
'0.9.0'
Instance Method Summary collapse
-
#os_name(os = nil, version = nil) ⇒ String
Return Operating System name with given os and version.
Instance Method Details
#os_name(os = nil, version = nil) ⇒ String
Return Operating System name with given os and version.
Usage: > os_name ‘darwin’, ‘14.0.0’
> ‘OS X Yosemite’
> os_name ‘linux’, ‘3.13.0-24-generic’
> ‘Linux 3.13’
os_name ‘win32’, ‘5.1.2600’
> ‘Windows XP’
os_name ‘win32’
> ‘Windows’
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/os_name.rb', line 48 def os_name os=nil, version=nil if !os && version raise ArgumentError, "You can't specify a `version` without specfying `os`" end os ||= platform.os version ||= platform.version case os when 'darwin' id = OSX.fetch version.split('.')[0] 'OS X' + (id ? " #{id}" : '') when 'linux' id = version.sub(/^(\d+\.\d+).*/, '\1') 'Linux' + (id ? " #{id}" : '') when 'win32' id = WIN32[version.slice(0, 3)] 'Windows' + (id ? " #{id}" : '') end end |