Class: String

Inherits:
Object show all
Defined in:
lib/tesler/ext.rb

Overview

define an extension for the String class

Instance Method Summary collapse

Instance Method Details

#teslerObject

actions :

  • replace the Windows directory separtor () by the unix separator (/)

  • replace tokens matching the format %TOKEN% by an environment variable



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tesler/ext.rb', line 14

def tesler
  # replace separators

  s = File.join self.split("\\")

  # environment variables

  env_vars = self.scan(/%([a-zA-Z_]+)%/).map { |array| array.first }
  env_vars.each do |var|
    s.gsub!(Regexp.new("%#{var}%"), ENV[var])
  end

  File.join s.split("\\")
end