Class: TTY::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/platform.rb,
lib/tty/platform/version.rb

Overview

Detects system platform properties

Constant Summary collapse

WINDOWS_PATTERN =
/(cygwin|mswin|mingw|bccwin|wince|emx)/i
UNIX_PATTERN =
/(aix|arch|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
LINUX_PATTERN =
/linux|arch/i
MAC_PATTERN =
/darwin/i
VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arch = nil) ⇒ Platform

Create platform properties



38
39
40
# File 'lib/tty/platform.rb', line 38

def initialize(arch = nil)
  @cpu, @os, @version = *detect_system_properties(arch)
end

Instance Attribute Details

#cpuObject (readonly)

Returns processor name, e.g. ‘amdk6’



23
24
25
# File 'lib/tty/platform.rb', line 23

def cpu
  @cpu
end

#osObject (readonly)

Returns the system/OS name, e.g. ‘darwin’



28
29
30
# File 'lib/tty/platform.rb', line 28

def os
  @os
end

#versionObject (readonly)

Returns system’s release version, e.g. ‘10.8.1’



33
34
35
# File 'lib/tty/platform.rb', line 33

def version
  @version
end

Instance Method Details

#architectureString

Queries for system architecture information

Returns:

  • (String)


79
80
81
# File 'lib/tty/platform.rb', line 79

def architecture
  RbConfig::CONFIG['arch']
end

#match_os?(matcher) ⇒ Boolean

Check if platform matches given systems

Returns:

  • (Boolean)


70
71
72
# File 'lib/tty/platform.rb', line 70

def match_os?(matcher)
  !!(@os =~ matcher)
end

#to_aArray[String]

Returns:

  • (Array[String])


86
87
88
# File 'lib/tty/platform.rb', line 86

def to_a
  [@cpu, @os, @version]
end

#to_sObject

String representation



93
94
95
# File 'lib/tty/platform.rb', line 93

def to_s
  to_a.compact.join('-')
end

#windows_file_path?Boolean

Detect if using windows path delimiter

Returns:

  • (Boolean)


61
62
63
# File 'lib/tty/platform.rb', line 61

def windows_file_path?
  ::File::ALT_SEPARATOR == '\\'
end