Class: ConvertGlobalEnv::ConvertGlobalEnv
- Inherits:
-
Object
- Object
- ConvertGlobalEnv::ConvertGlobalEnv
- Defined in:
- lib/convert_global_env/class/convert_global_env.rb
Overview
ConvertGlobalEnv::ConvertGlobalEnv
Class Method Summary collapse
-
.[](i = '') ⇒ Object
# === ConvertGlobalEnv::ConvertGlobalEnv[].
Instance Method Summary collapse
-
#do_the_conversion(input = input_string? ) ⇒ Object
(also: #convert)
# === do_the_conversion.
-
#hash_containing_the_environment_values? ⇒ Boolean
(also: #hash?)
# === hash_containing_the_environment_values? ========================================================================= #.
-
#initialize(i = ARGV, run_already = true) ⇒ ConvertGlobalEnv
constructor
# === initialize ========================================================================= #.
-
#input_string? ⇒ Boolean
(also: #input?)
# === input_string? ========================================================================= #.
-
#load_values_from_the_rcfiles_gem ⇒ Object
(also: #load_custom_file)
# === load_values_from_the_rcfiles_gem.
-
#regex_to_use? ⇒ Boolean
(also: #main_regex?)
# === regex_to_use?.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_input_string(i = '') ⇒ Object
# === set_input_string ========================================================================= #.
-
#translated_string? ⇒ Boolean
(also: #result?)
# === translated_string? ========================================================================= #.
Constructor Details
#initialize(i = ARGV, run_already = true) ⇒ ConvertGlobalEnv
#
initialize
#
27 28 29 30 31 32 33 34 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 27 def initialize( i = ARGV, run_already = true ) reset set_input_string(i) run if run_already end |
Class Method Details
.[](i = '') ⇒ Object
#
ConvertGlobalEnv::ConvertGlobalEnv[]
Usage example:
x = ConvertGlobalEnv::ConvertGlobalEnv['umount $USB3']
#
149 150 151 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 149 def self.[](i = '') new(i) end |
Instance Method Details
#do_the_conversion(input = input_string? ) ⇒ Object Also known as: convert
#
do_the_conversion
This is the method that does the actual conversion.
#
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 112 def do_the_conversion( input = input_string? ) regex = regex_to_use? @translated_string = input.dup # Keep a reference copy here. if input.include? '$' input =~ regex this_env_was_found = $1.to_s.dup # ===================================================================== # # Next check whether our main hash contains these environment # values or not. # ===================================================================== # if @hash_containing_the_environment_values.include? this_env_was_found @translated_string = input.gsub( /#{this_env_was_found}/, @hash_containing_the_environment_values[this_env_was_found] ).delete('$') end end return @translated_string end |
#hash_containing_the_environment_values? ⇒ Boolean Also known as: hash?
#
hash_containing_the_environment_values?
#
56 57 58 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 56 def hash_containing_the_environment_values? @hash_containing_the_environment_values end |
#input_string? ⇒ Boolean Also known as: input?
#
input_string?
#
87 88 89 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 87 def input_string? @input_string end |
#load_values_from_the_rcfiles_gem ⇒ Object Also known as: load_custom_file
#
load_values_from_the_rcfiles_gem
Only call this method if the rcfiles gem is installed, and if you really want to use the values from the .yml file that is contained in the rcfiles gem.
#
67 68 69 70 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 67 def load_values_from_the_rcfiles_gem require 'rcfiles' @hash_containing_the_environment_values = YAML.load_file(Rcfiles.file_global_variables) end |
#regex_to_use? ⇒ Boolean Also known as: main_regex?
#
regex_to_use?
Refer to the main regex for this project.
#
96 97 98 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 96 def regex_to_use? REGEX_TO_CHECK_FOR_GLOBAL_ENV end |
#reset ⇒ Object
#
reset (reset tag)
#
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 39 def reset # ======================================================================= # # === @translated_string # ======================================================================= # @translated_string = ''.dup # ======================================================================= # # === @hash_containing_the_environment_values # # This Hash can also be different, but by default it will refer to # the ENV variable. # ======================================================================= # @hash_containing_the_environment_values = ENV end |
#run ⇒ Object
#
run (run tag)
#
103 104 105 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 103 def run do_the_conversion end |
#set_input_string(i = '') ⇒ Object
#
set_input_string
#
75 76 77 78 79 80 81 82 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 75 def set_input_string(i = '') i = [i].flatten.compact.join(' ').strip unless i.encoding.to_s == ::ConvertGlobalEnv.encoding? i = i.dup if i.frozen? i = i.force_encoding(::ConvertGlobalEnv.encoding?) end @input_string = i end |
#translated_string? ⇒ Boolean Also known as: result?
#
translated_string?
#
137 138 139 |
# File 'lib/convert_global_env/class/convert_global_env.rb', line 137 def translated_string? @translated_string end |