Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#camelizeString

Find words, capitalize and join

Returns:

  • (String)

    camel cased string



5
6
7
# File 'lib/core_ext/string.rb', line 5

def camelize
  self.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
end

#no_erbString

Remove the erb extension if there is one

Returns:

  • (String)

    string with no erb extension



26
27
28
# File 'lib/core_ext/string.rb', line 26

def no_erb
  self.sub(/\.erb$/,'')
end

#substitute_env_varsString

Replace dollar-curly braces, with the value of environment variable

Returns:

  • (String)

    string with all environment variables replaced



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/core_ext/string.rb', line 34

def substitute_env_vars
  str = String.new(self)
  str.scan(/\$\{([A-Z][A-Z,0-9,_]*)\}/).uniq.each do |m|
    begin
      str.gsub!("${#{m[0]}}", ENV[m[0]])
    rescue
      $stderr.puts "problem with enviroment variable #{m[0]}."
    end
  end
  str
end

#underscoreizeString

Find words breaks and insert underscores

Returns:

  • (String)

    underscorized string



13
14
15
16
17
18
19
# File 'lib/core_ext/string.rb', line 13

def underscoreize
  self.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end