class KXI::Platform
Represents an platform of execution
Constants
- LINUX
Linux-based system
- OSX
Apple macOS
- WINDOWS
Microsoft Windows
Public Class Methods
Gets an environment variable @return [string] Value of environment variable if found; otherwise nil
# File lib/kxi/platform.rb, line 96 def self.env(key) key = key.downcase ENV.each_pair do |k, v| return v if k.downcase == key end return nil end
Instantiates the {KXI::Platform} class @param [string] nm Name of platform @param [string] ver Version of platform @param [string] ds Directory separator @param [string] ps Path separator @param [string] cs Determines whether paths are case-sensitive @param [string] libs File extensions of libraries
# File lib/kxi/platform.rb, line 57 def initialize(nm, ver, ds, ps, cs, *libs) @name = nm @version = KXI::Application::Version.parse(ver) @ds = ds @ps = ps @cs = cs @libs = libs end
Gets the current platform @return [KXI::Platform] Current platform
# File lib/kxi/platform.rb, line 68 def self.this return @@this if @@this != nil if /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM @@this = Platform.new(WINDOWS, `wmic os get Version /value`.split('=').last.strip.chomp, '\\', ';', false, 'dll') elsif /darwin/ =~ RUBY_PLATFORM @@this = Platform.new(OSX, `defaults read loginwindow SystemVersionStampAsString`, '/', ':', true, 'dylib') else @@this = Platform.new(LINUX, `uname -r`.split('-')[0], '/', ':', true, 'so') end return @@this end
Public Instance Methods
Gets the separator of directories within a path @return [string] Separator of directories
# File lib/kxi/platform.rb, line 40 def directory_separator @ds end
Finds an executable within the PATH of platform @return [string,nil] Path of executable if found; otherwise nil
# File lib/kxi/platform.rb, line 82 def exec(name, *dir) dir = Platform.env('path').split(@ps) if dir.length == 0 ext = Platform.env('pathext') (ext != nil ? ext.split(@ps) + [''] : ['']).each do |e| dir.each do |d| f = File.join(d, "#{name}#{e}") return f if File.exists?(f) end end return nil end
Gets the file extensions of libraries @return [Array<string>] File extensions of libraries
# File lib/kxi/platform.rb, line 28 def library_extensions @libs end
Gets the name of platform @return [string] Name of platform
# File lib/kxi/platform.rb, line 16 def name @name end
Determines whether paths are case-sensitive @return [bool] True if paths are case-sensitive; false otherwise
# File lib/kxi/platform.rb, line 46 def path_case_sensitive? @cs end
Gets the separator of paths @return [string] Separator of paths
# File lib/kxi/platform.rb, line 34 def path_separator @ps end
Gets the version of platform @return [KXI::Application::Version] Version of platform
# File lib/kxi/platform.rb, line 22 def version @version end