Class: ConvertGlobalEnv::ConvertGlobalEnv
- Inherits:
-
Object
- Object
- ConvertGlobalEnv::ConvertGlobalEnv
show all
- Defined in:
- lib/convert_global_env/class/convert_global_env.rb
Overview
ConvertGlobalEnv::ConvertGlobalEnv
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(i = ARGV, run_already = true) ⇒ ConvertGlobalEnv
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 if input.include? '$'
input =~ regex
this_env_was_found = $1.to_s.dup
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
|
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.
#
#reset ⇒ Object
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 = ''.dup
@hash_containing_the_environment_values = ENV
end
|
#run ⇒ Object
103
104
105
|
# File 'lib/convert_global_env/class/convert_global_env.rb', line 103
def run
do_the_conversion
end
|
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?
137
138
139
|
# File 'lib/convert_global_env/class/convert_global_env.rb', line 137
def translated_string?
@translated_string
end
|