diff options
Diffstat (limited to 'lib/expand_variables.rb')
-rw-r--r-- | lib/expand_variables.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/expand_variables.rb b/lib/expand_variables.rb new file mode 100644 index 00000000000..40bf9483eb5 --- /dev/null +++ b/lib/expand_variables.rb @@ -0,0 +1,15 @@ +String.instance_eval + def expand_variables(variables) + # Convert hash array to variables + if variables.is_a?(Array) + variables = variables.reduce({}) do |hash, variable| + hash[variable[:key]] = variable[:value] + hash + end + end + + self.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do + variables[$1 || $2] + end + end +end |