Class: TTY::Platform
- Inherits:
-
Object
- Object
- TTY::Platform
- 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
-
#cpu ⇒ Object
readonly
Returns processor name, e.g.
-
#os ⇒ Object
readonly
Returns the system/OS name, e.g.
-
#version ⇒ Object
readonly
Returns system’s release version, e.g.
Instance Method Summary collapse
-
#architecture ⇒ String
Queries for system architecture information.
-
#initialize(arch = nil) ⇒ Platform
constructor
Create platform properties.
-
#match_os?(matcher) ⇒ Boolean
Check if platform matches given systems.
- #to_a ⇒ Array[String]
-
#to_s ⇒ Object
String representation.
-
#windows_file_path? ⇒ Boolean
Detect if using windows path delimiter.
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
#cpu ⇒ Object (readonly)
Returns processor name, e.g. ‘amdk6’
23 24 25 |
# File 'lib/tty/platform.rb', line 23 def cpu @cpu end |
#os ⇒ Object (readonly)
Returns the system/OS name, e.g. ‘darwin’
28 29 30 |
# File 'lib/tty/platform.rb', line 28 def os @os end |
#version ⇒ Object (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
#architecture ⇒ String
Queries for system architecture information
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
70 71 72 |
# File 'lib/tty/platform.rb', line 70 def match_os?(matcher) !!(@os =~ matcher) end |
#to_a ⇒ Array[String]
86 87 88 |
# File 'lib/tty/platform.rb', line 86 def to_a [@cpu, @os, @version] end |
#to_s ⇒ Object
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
61 62 63 |
# File 'lib/tty/platform.rb', line 61 def windows_file_path? ::File::ALT_SEPARATOR == '\\' end |