Module: Env::Variables

Included in:
Env
Defined in:
lib/env/variables.rb

Instance Method Summary collapse

Instance Method Details

#browserString?

The default browser to use.

Returns:

  • (String, nil)

    The name of the browser program.



182
183
184
# File 'lib/env/variables.rb', line 182

def browser
  env['BROWSER']
end

#columnsInteger

The number of columns in the terminal.

Returns:

  • (Integer)

    The number of columns.



122
123
124
# File 'lib/env/variables.rb', line 122

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

#debug?Boolean

Determines whether optional Debugging was enabled.

Returns:

  • (Boolean)

    Specifies whether the DEBUG variable was specified.

Since:

  • 0.2.0



194
195
196
# File 'lib/env/variables.rb', line 194

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

#editorString?

The default editor to use.

Returns:

  • (String, nil)

    The name of the editor program.



172
173
174
# File 'lib/env/variables.rb', line 172

def editor
  env['EDITOR']
end

#envHash{String => String}

The environment variables.

Returns:

  • (Hash{String => String})

    The Hash of environment variable names and values.



13
14
15
# File 'lib/env/variables.rb', line 13

def env
  ENV
end

#homePathname

The home directory.

Returns:

  • (Pathname)

    The path of the home directory.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/env/variables.rb', line 69

def home
  # logic adapted from Gem.find_home.
  path = if (env['HOME'] || env['USERPROFILE'])
           env['HOME'] || env['USERPROFILE']
         elsif (env['HOMEDRIVE'] && env['HOMEPATH'])
           "#{env['HOMEDRIVE']}#{env['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.

Since:

  • 0.3.0



45
46
47
# File 'lib/env/variables.rb', line 45

def host_name
  env['HOSTNAME']
end

#langArray<String, String>

The default language.

Returns:

  • (Array<String, String>)

    The language name and encoding.



96
97
98
99
100
101
102
# File 'lib/env/variables.rb', line 96

def lang
  if (lang = env['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.



33
34
35
# File 'lib/env/variables.rb', line 33

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

#linesInteger

The number of lines in the terminal.

Returns:

  • (Integer)

    The number of lines.



132
133
134
# File 'lib/env/variables.rb', line 132

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

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

Parses a String containing multiple paths.

Returns:

  • (Array<Pathname>)

    The multiple paths.



206
207
208
209
210
211
212
213
214
# File 'lib/env/variables.rb', line 206

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.



23
24
25
# File 'lib/env/variables.rb', line 23

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

#shellString?

The path of the default shell.

Returns:

  • (String, nil)

    The path to the default shell.



142
143
144
# File 'lib/env/variables.rb', line 142

def shell
  env['SHELL']
end

#shell_nameString?

The name of the default shell.

Returns:

  • (String, nil)

    The program name of the shell.



152
153
154
# File 'lib/env/variables.rb', line 152

def shell_name
  File.basename(shell) if shell
end

#terminalString?

The default terminal to use.

Returns:

  • (String, nil)

    The name of the terminal program.



162
163
164
# File 'lib/env/variables.rb', line 162

def terminal
  env['COLORTERM'] || env['TERM']
end

#timezoneString?

The default timezone.

Returns:

  • (String, nil)

    The timezone name.

Since:

  • 0.2.0



112
113
114
# File 'lib/env/variables.rb', line 112

def timezone
  env['TZ']
end

#userString

The name of the current user.

Returns:

  • (String)

    The name of the user.

Since:

  • 0.3.0



57
58
59
60
61
# File 'lib/env/variables.rb', line 57

def user
  # USER is used on GNU/Linux and Windows
  # LOGNAME is the POSIX user-name ENV variable
  env['USER'] || env['LOGNAME']
end