class String
Monkey patches for Mysh
handlebars
Monkey patches for Mysh
variables
Monkey patches for Mysh
string data.
Public Instance Methods
dress_up_quotes()
click to toggle source
Dress up in quotes if needed.
# File lib/mysh/string_helpers.rb, line 23 def dress_up_quotes self[' '] ? "\"#{self}\"" : self end
dress_up_slashes()
click to toggle source
Dress up slashes and backslashes.
# File lib/mysh/string_helpers.rb, line 18 def dress_up_slashes MiniTerm.windows? ? self.gsub("/", "\\") : self end
eval_handlebars(evaluator=$mysh_exec_binding)
click to toggle source
Evaluate any variable substitutions in the input.
# File lib/mysh/handlebars/eval_handlebars.rb, line 7 def eval_handlebars(evaluator=$mysh_exec_binding) string, text, buffer = self, "", [] # Translate the string with embedded code into Ruby code. until string.empty? text, code, string = string.partition(/{{.*?}}/m) unless text.empty? text = text.gsub(/\\[{}]/) {|found| found[1]} buffer << "_m_<<#{text.inspect};" else buffer << "" if buffer.empty? end unless code.empty? if code[-3] == "#" buffer << "#{code[2...-3]};" else buffer << "_m_<<(#{code[2...-2]}).to_s;" end end end # Evaluate the result of the translation. if buffer.length > 1 evaluator.eval("_m_ = '';" + buffer.join + "_m_") else text end end
eval_variables()
click to toggle source
Evaluate any variable substitutions in the string.
# File lib/mysh/shell_variables/evaluate.rb, line 7 def eval_variables self.gsub(/((?<!\\)\$\$)|((?<!\\)\$[a-z][a-z0-9_]*)/) do |str| sym = str[1..-1].to_sym MNV.key?(sym) ? MNV[sym].to_s : str end.gsub(/\\\$/, "$") end
extract_boolean()
click to toggle source
Extract Boolean data from this string.
# File lib/mysh/string_helpers.rb, line 7 def extract_boolean self !~ /\A(false|no|off)?\z/i end
preprocess(evaluator=$mysh_exec_binding)
click to toggle source
The mysh string pre-processor stack.
# File lib/mysh/string_helpers.rb, line 33 def preprocess(evaluator=$mysh_exec_binding) self.eval_variables.eval_handlebars(evaluator) end
to_host_spec()
click to toggle source
Make the file name fit the local system.
# File lib/mysh/string_helpers.rb, line 12 def to_host_spec self.dress_up_slashes .dress_up_quotes end
to_std_spec()
click to toggle source
Make the file name fit the standard notation.
# File lib/mysh/string_helpers.rb, line 28 def to_std_spec self.gsub("\\", "/") end