module EnvExt::Methods

Public Instance Methods

browser() click to toggle source

The default browser to use.

@return [String, nil]

The name of the browser program.
# File lib/env_ext/methods.rb, line 166
def browser
  self['BROWSER']
end
columns() click to toggle source

The number of columns in the terminal.

@return [Integer]

The number of columns.
# File lib/env_ext/methods.rb, line 104
def columns
  self['COLUMNS'].to_i if self['COLUMNS']
end
debug?() click to toggle source

Determines whether optional Debugging was enabled.

@return [Boolean]

Specifies whether the `DEBUG` variable was specified.
# File lib/env_ext/methods.rb, line 176
def debug?
  true if self['DEBUG']
end
editor() click to toggle source

The default editor to use.

@return [String, nil]

The name of the editor program.
# File lib/env_ext/methods.rb, line 156
def editor
  self['EDITOR']
end
home() click to toggle source

The home directory.

@return [Pathname]

The path of the home directory.
# File lib/env_ext/methods.rb, line 53
def home
  # logic adapted from Gem.find_home.
  path = if (self['HOME'] || self['USERPROFILE'])
           self['HOME'] || self['USERPROFILE']
         elsif (self['HOMEDRIVE'] && self['HOMEPATH'])
           "#{self['HOMEDRIVE']}#{self['HOMEPATH']}"
         else
           begin
             File.expand_path('~')
           rescue
             if File::ALT_SEPARATOR
               'C:/'
             else
               '/'
             end
           end
         end

  return Pathname.new(path)
end
host_name() click to toggle source

The host-name of the system.

@return [String]

The host-name.
# File lib/env_ext/methods.rb, line 31
def host_name
  self['HOSTNAME']
end
lang() click to toggle source

The default language.

@return [Array<String, String>]

The language name and encoding.
# File lib/env_ext/methods.rb, line 80
def lang
  if (lang = self['LANG'])
    lang.split('.',2)
  else
    []
  end
end
ld_library_paths() click to toggle source

The directories to search within for libraries.

@return [Array<Pathname>]

The paths of the directories.
# File lib/env_ext/methods.rb, line 21
def ld_library_paths
  parse_paths(self['LD_LIBRARY_PATH'])
end
lines() click to toggle source

The number of lines in the terminal.

@return [Integer]

The number of lines.
# File lib/env_ext/methods.rb, line 114
def lines
  self['LINES'].to_i if self['LINES']
end
paths() click to toggle source

The directories to search within for executables.

@return [Array<Pathname>]

The paths of the directories.
# File lib/env_ext/methods.rb, line 11
def paths
  parse_paths(self['PATH'])
end
shell() click to toggle source

The path of the default shell.

@return [String, nil]

The path to the default shell.
# File lib/env_ext/methods.rb, line 124
def shell
  self['SHELL']
end
shell_name() click to toggle source

The name of the default shell.

@return [String, nil]

The program name of the shell.
# File lib/env_ext/methods.rb, line 134
def shell_name
  File.basename(shell) if shell
end
term() click to toggle source

The default terminal to use.

@return [String, nil]

The name of the terminal program.
# File lib/env_ext/methods.rb, line 144
def term
  self['COLORTERM'] || self['TERM']
end
Also aliased as: terminal
terminal()
Alias for: term
timezone() click to toggle source

The default timezone.

@return [String, nil]

The timezone name.
# File lib/env_ext/methods.rb, line 94
def timezone
  self['TZ']
end
user() click to toggle source

The name of the current user.

@return [String]

The name of the user.
# File lib/env_ext/methods.rb, line 41
def user
  # USER is used on GNU/Linux and Windows
  # LOGNAME is the POSIX user-name ENV variable
  self['USER'] || self['LOGNAME']
end

Protected Instance Methods

parse_paths(paths) click to toggle source

Parses a String containing multiple paths.

@return [Array<Pathname>]

The multiple paths.
# File lib/env_ext/methods.rb, line 188
def parse_paths(paths)
  if paths
    paths.split(File::PATH_SEPARATOR).map do |path|
      Pathname.new(path)
    end
  else
    []
  end
end