Module: EnvExt::Methods

Defined in:
lib/env_ext/methods.rb

Instance Method Summary collapse

Instance Method Details

#browserString?

The default browser to use.

Returns:

  • (String, nil)

    The name of the browser program.



166
167
168
# File 'lib/env_ext/methods.rb', line 166

def browser
  self['BROWSER']
end

#columnsInteger

The number of columns in the terminal.

Returns:

  • (Integer)

    The number of columns.



104
105
106
# File 'lib/env_ext/methods.rb', line 104

def columns
  self['COLUMNS'].to_i if self['COLUMNS']
end

#debug?Boolean

Determines whether optional Debugging was enabled.

Returns:

  • (Boolean)

    Specifies whether the DEBUG variable was specified.



176
177
178
# File 'lib/env_ext/methods.rb', line 176

def debug?
  true if self['DEBUG']
end

#editorString?

The default editor to use.

Returns:

  • (String, nil)

    The name of the editor program.



156
157
158
# File 'lib/env_ext/methods.rb', line 156

def editor
  self['EDITOR']
end

#homePathname

The home directory.

Returns:

  • (Pathname)

    The path of the home directory.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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_nameString

The host-name of the system.

Returns:

  • (String)

    The host-name.



31
32
33
# File 'lib/env_ext/methods.rb', line 31

def host_name
  self['HOSTNAME']
end

#langArray<String, String>

The default language.

Returns:

  • (Array<String, String>)

    The language name and encoding.



80
81
82
83
84
85
86
# File 'lib/env_ext/methods.rb', line 80

def lang
  if (lang = self['LANG'])
    lang.split('.',2)
  else
    []
  end
end

#ld_library_pathsArray<Pathname>

The directories to search within for libraries.

Returns:

  • (Array<Pathname>)

    The paths of the directories.



21
22
23
# File 'lib/env_ext/methods.rb', line 21

def ld_library_paths
  parse_paths(self['LD_LIBRARY_PATH'])
end

#linesInteger

The number of lines in the terminal.

Returns:

  • (Integer)

    The number of lines.



114
115
116
# File 'lib/env_ext/methods.rb', line 114

def lines
  self['LINES'].to_i if self['LINES']
end

#parse_paths(paths) ⇒ Array<Pathname> (protected)

Parses a String containing multiple paths.

Returns:

  • (Array<Pathname>)

    The multiple paths.



188
189
190
191
192
193
194
195
196
# 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

#pathsArray<Pathname>

The directories to search within for executables.

Returns:

  • (Array<Pathname>)

    The paths of the directories.



11
12
13
# File 'lib/env_ext/methods.rb', line 11

def paths
  parse_paths(self['PATH'])
end

#shellString?

The path of the default shell.

Returns:

  • (String, nil)

    The path to the default shell.



124
125
126
# File 'lib/env_ext/methods.rb', line 124

def shell
  self['SHELL']
end

#shell_nameString?

The name of the default shell.

Returns:

  • (String, nil)

    The program name of the shell.



134
135
136
# File 'lib/env_ext/methods.rb', line 134

def shell_name
  File.basename(shell) if shell
end

#termString? Also known as: terminal

The default terminal to use.

Returns:

  • (String, nil)

    The name of the terminal program.



144
145
146
# File 'lib/env_ext/methods.rb', line 144

def term
  self['COLORTERM'] || self['TERM']
end

#timezoneString?

The default timezone.

Returns:

  • (String, nil)

    The timezone name.



94
95
96
# File 'lib/env_ext/methods.rb', line 94

def timezone
  self['TZ']
end

#userString

The name of the current user.

Returns:

  • (String)

    The name of the user.



41
42
43
44
45
# 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